plotting and some other stuff

This commit is contained in:
Erik Grobecker 2024-10-20 15:41:29 +02:00
parent 04a3fa6163
commit e0d007d99e
Signed by: Erik
GPG key ID: 80D020D0ABBD3FB2
7 changed files with 134 additions and 4 deletions

6
.gitmodules vendored Normal file
View file

@ -0,0 +1,6 @@
[submodule "libs/cetz-plot"]
path = libs/cetz-plot
url = https://github.com/cetz-package/cetz-plot
[submodule "libs/cetz"]
path = libs/cetz
url = https://github.com/cetz-package/cetz

View file

@ -1,4 +1,8 @@
# Random Typstery
![Gitea Issues](https://img.shields.io/gitea/issues/open/erik/typst?gitea_url=https%3A%2F%2Fgit.grobecker.me&style=for-the-badge)
![Gitea Last Commit](https://img.shields.io/gitea/last-commit/erik/typst?gitea_url=https%3A%2F%2Fgit.grobecker.me&style=for-the-badge)
In diesem Projekt schreibe ich zufällige Sachen(meisten für die Schule) mit [typst](https://typst.app),\
diese sind gestützt von meiner [Vorlage](./template.typ) welche ich immer weiter verbessern werde.

View file

@ -34,10 +34,10 @@
#show link: set text(rgb("#1470da"))
// here are replacements for commonly used shortcuts
#show "z.B.": text[zum Beispiel]
#show "zb": "zumb Beispiel"
#show "z.B.": "zum Beispiel"
#show "zb": "zum Beispiel"
#show "vllt": "vielleicht"
#show "CO2": $"CO"_2$
#body // IMPORTANT: must be at the very bottom, ekse the body will be overwritten
#body // IMPORTANT: must be at the very bottom, else the body will be overwritten
]

55
testing/cetz-plot.typ Normal file
View file

@ -0,0 +1,55 @@
#import "@preview/cetz:0.2.2"
#set page(width: auto, height: auto, margin: .5cm)
#show math.equation: block.with(fill: white, inset: 1pt) //for not showing the grid on math
#cetz.canvas(length: 3cm, {
import cetz.draw: *
set-style(
mark: (fill: black, scale: 2),
stroke: (thickness: 0.4pt, cap: "round"),
angle: (
radius: 0.3,
label-radius: .22,
fill: green.lighten(80%),
stroke: (paint: green.darken(50%))
),
content: (padding: 1pt)
)
grid((-1.5, -1.5), (1.4, 1.4), step: 0.5, stroke: gray + 0.2pt)
circle((0,0), radius: 1)
line((-1.5, 0), (1.5, 0), mark: (end: "stealth"))
content((), $ x $, anchor: "west")
line((0, -1.5), (0, 1.5), mark: (end: "stealth"))
content((), $ y $, anchor: "south")
for (x, ct) in ((-1, $ -1 $), (-0.5, $ -1/2 $), (1, $ 1 $)) {
line((x, 3pt), (x, -3pt))
content((), anchor: "north", ct)
}
for (y, ct) in ((-1, $ -1 $), (-0.5, $ -1/2 $), (0.5, $ 1/2 $), (1, $ 1 $)) {
line((3pt, y), (-3pt, y))
content((), anchor: "east", ct)
}
// Draw the green angle
cetz.angle.angle((0,0), (1,0), (1, calc.tan(30deg)),
label: text(green, [#sym.alpha]))
line((0,0), (1, calc.tan(30deg)))
set-style(stroke: (thickness: 1.2pt))
line((30deg, 1), ((), "|-", (0,0)), stroke: (paint: red), name: "sin")
content(("sin.start", 50%, "sin.end"), text(red)[$ sin alpha $])
line("sin.end", (0,0), stroke: (paint: blue), name: "cos")
content(("cos.start", 50%, "cos.end"), text(blue)[$ cos alpha $], anchor: "north")
line((1, 0), (1, calc.tan(30deg)), name: "tan", stroke: (paint: orange))
content("tan.end", $ text(#orange, tan alpha) = text(#red, sin alpha) / text(#blue, cos alpha) $, anchor: "west")
})

BIN
testing/cetz.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

65
testing/cetz.typ Normal file
View file

@ -0,0 +1,65 @@
// #import "@preview/cetz:0.2.2": canvas, plot
#set page(width: auto, height: auto, margin: .5cm)
// #let style = (stroke: black, fill: rgb(0, 0, 200, 75))
// #canvas(length: 1cm, {
// plot.plot(size: (8, 6),
// x-tick-step: none,
// x-ticks: ((-calc.pi, $-pi$), (0, $0$), (calc.pi, $pi$)),
// y-tick-step: 1,
// {
// plot.add(
// style: style,
// domain: (-calc.pi, calc.pi), calc.sin)
// plot.add(
// hypograph: true,
// style: style,
// domain: (-calc.pi, calc.pi), calc.cos)
// plot.add(
// hypograph: true,
// style: style,
// domain: (-calc.pi, calc.pi), x => calc.cos(x + calc.pi))
// })
// })
// #canvas(length: 1cm, {
// plot.plot(size: (-10, 10),
// {},
// )
// })
#import "@preview/cetz:0.2.2"
// #cetz.canvas({
// import cetz.draw: *
// import cetz.plot
// plot.plot(size: (2,2), x-tick-step: 2, y-tick-step: 2, x-equal: "y",
// {
// plot.add(((0,0), (1,1), (2,.5), (4,3)))
// plot.add(domain: (0, 2 * calc.pi),
// t => (calc.cos(t), calc.sin(t))
// )
// })
// })
#cetz.canvas({
import cetz.draw: *
import cetz.plot
plot.plot(size: (10, 4), x-tick-step: 2, y-tick-step: 50,
{
plot.add(domain: (-4, 4),
x => (x, calc.pow(x, 4) ),
label: $f(x)=x^4$
)
plot.add(domain: (-5, 6.34),
x => (x, calc.pow(x, 3)),
label: $f(x)=x^3$
)
plot.add(domain: (-10, 10),
x => (x, calc.pow(x, 2)),
label: $f(x) = x^2$
)
})
})