-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting tangents and coordinates of evenly spaced points on kurbo::BezPath #338
Comments
One way could be: iterate over segments of This solution is probably bit naive for Bezier segments as pointed out here. But it should work as expected for purely linear paths, like ways in OpenStreetMap data. use kurbo::{BezPath, ParamCurve, ParamCurveArclen, ParamCurveDeriv, PathSeg, Point, Vec2};
fn eval_spacing(path: &BezPath, start_offset: f64, spacing: f64) -> Vec<(Point, Vec2)> {
let mut target_length = start_offset;
let mut prev_length = 0.0;
let mut result = vec![];
for seg in path.segments() {
let seg_length = seg.arclen(1e-3);
// are we inside current segment?
while (target_length - prev_length) <= seg_length {
// local t parameter for segment in range 0.0..1.0
let t = (target_length - prev_length) / seg_length;
// obtain curve point and tangent
let p = seg.eval(t);
let tangent = match seg {
PathSeg::Quad(s) => s.deriv().eval(t).to_vec2(),
PathSeg::Cubic(s) => s.deriv().eval(t).to_vec2(),
PathSeg::Line(s) => s.deriv().eval(t).to_vec2(),
};
result.push((p, tangent));
// move to next spacing
target_length += spacing;
}
// mark covered length
prev_length += seg_length;
}
result
} There is maybe better way to obtain tangent, but it is already late evening here >.> Traits |
So I've forgot about So instead of line let t = (target_length - prev_length) / seg_length; it should be: let t = seg.inv_arclen(target_length - prev_length, 1e-3); Obviously one could pass higher accuracy. |
Thank you. |
Some of these should be implementable for BezPath. Probably not |
Implementing ParamCurveArclen for BezPath is going to be pretty inefficient, especially for the inverse arclengths (it will have to traverse the entire path). Fundamentally this problem is very much the same as the dash iterator for stroking, the best approach is probably to adapt that. |
Hello,
(How) Is it possible to get coordinates and tangents from kurbo::BezPath of evenly spaced points on a curve if I have a start offset and spacing? I would like to implement something like Mapnik's MarkersSymbolizer.
The text was updated successfully, but these errors were encountered: