the tangent function could be handled differently
#canvas(length:2cm,{
plot.plot(
size: (6,3),
y-max: 50,
y-min: -50,
plot.add(
x=>(x,calc.tan(x)),
samples: ???,
domain: (-15,15),
)
)
})
50 samples:
100 samples:
500 samples:
1000 samples:
5000 samples:
10000 samples:
The parts where the tangent goes to infinity gets connected sequentially to each other, and in some cases (as seen in the 5000 samples version) there's no connection, but the majority of the graph still have these unwanted connections.
Do you have some ideas how an API for this could look like?
I believe the intended result could be achieved by finding out where the limits don't exist (where $y$ goes to infinity).
with the following code I managed to make the tangent graph:
#cetz.canvas(length:2cm,{
plot.plot(
size: (7,3.5),
x-label: $x$,
x-tick-step: calc.pi/2,
x-format: plot.formats.multiple-of,
x-grid: "both",
y-label: $tan x$,
y-tick-step: 10,
y-grid: "both",
y-max: 20,
y-min: -20,
{
plot.add(
x=>(x,calc.tan(x)),
samples: 100,
domain: (-calc.pi*5/2,-calc.pi*3/2),
style: (stroke:(paint:green,thickness:2pt)),
)
plot.add(
x=>(x,calc.tan(x)),
samples: 100,
domain: (-calc.pi*3/2,-calc.pi*1/2),
style: (stroke:(paint:green,thickness:2pt)),
)
plot.add(
x=>(x,calc.tan(x)),
samples: 100,
domain: (-calc.pi*1/2,calc.pi*1/2),
style: (stroke:(paint:green,thickness:2pt)),
)
plot.add(
x=>(x,calc.tan(x)),
samples: 100,
domain: (calc.pi/2,calc.pi*3/2),
style: (stroke:(paint:green,thickness:2pt)),
)
plot.add(
x=>(x,calc.tan(x)),
samples: 100,
domain: (calc.pi*3/2,calc.pi*5/2),
style: (stroke:(paint:green,thickness:2pt)),
)
}
)
})
I had to make multiple plots whose domains are within areas that are continuous. A function is continuous in a point $a$ if: $lim_{x \to a} f(x) = f(a)$
By ceasing to draw the point where there is no limit, it could work.