cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
809 stars 35 forks source link

Tangent lines for bezier and catmull #451

Open JeyRunner opened 7 months ago

JeyRunner commented 7 months ago

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).

johannes-wolf commented 7 months ago

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.

JeyRunner commented 7 months ago

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 commented 7 months ago

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.