flo_curves icon indicating copy to clipboard operation
flo_curves copied to clipboard

[Question] Walk BezierPath evenly obtaining positions and tangents

Open zdila opened this issue 1 year ago • 2 comments

I am looking for a way to walk BezierPath evenly to get points and their tangents. I also need to specify initial offset (space). What would be a good approach for this?

zdila avatar Feb 14 '24 19:02 zdila

There's a function for this: walk_curve_evenly(). The EvenWalkIterator it returns has a vary_by() function that can be used to change the size of the following steps, so that can be used to skip a part at the start of the curve.

This function works using chord lengths (distance between points on the curve rather than the length of the curve itself), however, so it can lose accuracy if the steps are very large or at points where the curvature is very high. An uneven walk of the curve will return more dense points where the curvature is higher, so could be used to mitigate this.

v0.8 of flo_curves adds a flatness() function that can be used to subdivide curves into approximately straight line segments, which would further mitigate this problem (though I haven't added much yet to the library to use this for specific problems like this)

Logicalshift avatar Feb 23 '24 21:02 Logicalshift

Thank you. I actually ended with copy_path_flat as I am using Cairo-rs.

zdila avatar Feb 27 '24 11:02 zdila