cetz icon indicating copy to clipboard operation
cetz copied to clipboard

Tangent lines for bezier and catmull

Open JeyRunner opened this issue 2 years ago • 3 comments

When I am plotting a line (visualizes function $f(x)$ in cetz with bezier or catmull, I would like to add tangent lines for visualizing $f'(x)$ at different x positions of the line.

The tangent coordinate functionality that I tried using for this seems to not be intended for this usecase:

catmull(name: "line", ..points)
circle(name: "tangent_here", p, radius: 1mm, fill: white)
line("tangent_here", (element: "line", point: "tangent_here", solution: 0))

Which leads to the tangent lines not being perpendicular to the plot: grafik

The goal is to produce something like this: grafik

It would be nice to have some functionality to produce these tangent lines for arbitrary shapes (e.g. from catmull).

JeyRunner avatar Jan 13 '24 14:01 JeyRunner

Proposal: Have a more verbose (tangent: <distance, ratio>, on: <element>, [length: number=1]) and (normal: <distance, ratio>, on: <element>, [length: number=1]) to get a point on the tangent or normal of a path. The current tangent implementation is not very useful.

johannes-wolf avatar Jan 13 '24 18:01 johannes-wolf

Thanks, this looks like a good solution :+1: . Could the value of tangent then also be a point (that has to be on the line)? As I understand the proposal [tangent](tangent: <distance, ratio>) would be a scalar indicating the position on the line (e.g. 0-100%).

The point value for tangent would be useful when I have the exact x,y position where I want to insert the tangent/normal line.

JeyRunner avatar Jan 13 '24 18:01 JeyRunner

I also think that the current functionality should be retained (along with the proposal), as it can be used as in the example from the manual with a circle.

JeyRunner avatar Jan 13 '24 18:01 JeyRunner