cetz-plot icon indicating copy to clipboard operation
cetz-plot copied to clipboard

the tangent function could be handled differently

Open aabbccddeeffggj opened this issue 10 months ago • 2 comments

#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:

Image

100 samples:

Image

500 samples:

Image

1000 samples:

Image

5000 samples:

Image

10000 samples:

Image

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.

aabbccddeeffggj avatar Mar 30 '25 16:03 aabbccddeeffggj

Do you have some ideas how an API for this could look like?

johannes-wolf avatar Apr 06 '25 19:04 johannes-wolf

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)),
		)
		}
	)
})

Image

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.

aabbccddeeffggj avatar Apr 08 '25 22:04 aabbccddeeffggj