Expand description
polydf: Distance queries for parametric curves (2D and 3D).
- 2D curves: nearest point, unsigned and signed distance (using outward normal).
- 3D curves: nearest point and unsigned distance (no signed distance for space curves).
Example (3D helix):
use nalgebra::{Vector3, vector};
use polydf::{NearestOptions, nearest_t_3d, distance_to_curve_3d};
fn helix(t: f32) -> Vector3<f32> {
vector![t.cos(), t.sin(), 0.5 * t]
}
let p = vector![2.0, 0.0, 0.0];
let t_range = -10.0f32..=10.0f32;
let opts = NearestOptions::default();
let res = nearest_t_3d(p, helix, t_range.clone(), opts);
println!("t* = {} distance = {}", res.t, res.distance);
let d = distance_to_curve_3d(p, helix, t_range, opts);This crate provides routines to find the nearest parameter t and compute
the (optionally signed) distance from an arbitrary 2D point p to a
differentiable parametric curve C(t): f32 -> (f32, f32).
Key features:
- Works with any differentiable 2D parametric function (closures supported).
- Returns the nearest parameter
t, closest point, and (signed) distance. - Optional thresholded query with a conservative early-out if the point is provably farther than the threshold (requires a speed bound).
Notes on signed distance:
- The sign is defined using the outward normal estimated from the curve
tangent at the closest point. We take the outward normal as the tangent
rotated by -90 degrees, and define
signed_distance = (p - C(t*)) · n. For CCW-oriented closed curves, points outside are positive and inside are negative. For other orientations, the sign will be consistent but may flip depending on your curve’s direction.
Structs§
- Nearest
Options - Options controlling the search behavior.
- Nearest
Result - Result of a nearest-point query on a parametric curve.
- Nearest
Result3D - Result of a nearest-point query on a 3D parametric curve.
Functions§
- distance_
to_ curve - Return the unsigned distance from point
pto the curvef(t)overt_range. - distance_
to_ curve_ 3d - 3D: Return the unsigned distance from point
pto the curvef(t). - distance_
to_ curve_ tuple - Tuple-friendly unsigned distance from
(x, y)to curvef(t)int_range. - is_
definitely_ far - Attempt to quickly reject queries that are provably farther than
threshold. - is_
definitely_ far_ 3d - 3D variant: attempt to quickly reject queries that are provably farther
than
threshold, given an upper bound on the curve speed. - nearest_
t - Find nearest parameter
tto pointpon curvef(t)overt_range. - nearest_
t_ 3d - Find nearest parameter
tto pointpon a 3D curvef(t)overt_range. Returns the nearest parameter and unsigned distance. - nearest_
t_ tuple - Convenience wrapper for curves defined as
Fn(f32) -> (f32, f32)and points as tuples. - nearest_
t_ tuple_ 3d - Convenience wrapper for 3D curves defined as
Fn(f32) -> (f32, f32, f32)and points as tuples. - nearest_
t_ with_ derivative - Find nearest parameter
tusing both the curvefand its derivativedf. - nearest_
t_ with_ derivative_ tuple - Convenience wrapper for tuple-based curve and derivative.
- nearest_
t_ within - Thresholded query: if
speed_upper_boundis provided and the point is provably farther thanthreshold, returnsNonequickly. Otherwise falls back to a full nearest search and returns the result. - nearest_
t_ within_ 3d - 3D variant of thresholded query. If
speed_upper_boundis provided and the point is provably farther thanthreshold, returnsNone. Otherwise runs a full nearest search and returns the result. - nearest_
t_ within_ tuple - Convenience wrapper for thresholded query using tuple-based curve and point.
- within_
threshold - Return
trueif the point is withinthresholddistance of the curve. - within_
threshold_ 3d - 3D: Return
trueif the point is withinthresholddistance of the curve. - within_
threshold_ tuple - Tuple-friendly predicate: is
(x, y)withinthresholddistance of curvef?