Skip to main content

Crate clothoid

Crate clothoid 

Source
Expand description

§clothoid

A Rust library for computing and fitting Clothoids (also known as Euler spirals or Cornu spirals). A clothoid is a curve whose curvature changes linearly with its arc length.

§Usage

use clothoid::Clothoid;

let clothoid = Clothoid::new(1.0);
let angle = clothoid.direction_angle(0.5);

§Choosing an Optimizer

The FitState supports two derivative-free optimizers for path fitting:

  • Nelder-Mead (default) — The original simplex method. Fast per-iteration (500 evaluations per step), good for simple paths. Created with FitState::new(). Requires the nelder-mead feature (enabled by default).
  • CMA-ES — Covariance Matrix Adaptation Evolution Strategy. More robust on difficult, non-convex landscapes but evaluates more candidates per generation. Created with FitState::cma_es(). Requires the cma-es feature (enabled by default).

Both share the same FitState API. Press O in the interactive demo to toggle between them.

§Path Traits

When the path-traits feature is enabled (default), the crate provides ClothoidArc, LinearSegment, ClothoidPath, and Vec2 implementing the path_traits hierarchy. This allows downstream crates to treat clothoid paths generically via traits such as Path, SegmentedPath, Tangent, Heading, Curved, FrenetFrame, and Project.

use clothoid::ClothoidArc;
use clothoid::optimizer::Pose;
use path_traits::{Path, Heading, Curved};

let arc = ClothoidArc {
    start: Pose::new(0.0, 0.0, 0.0),
    ks: 0.0,
    ke: 1.0,
    length: 5.0,
    n_steps: 256,
};

let pt = arc.sample_at(2.5).unwrap();
let heading = arc.heading_at(2.5).unwrap();
let curvature = arc.curvature_at(2.5).unwrap();

Use Clothoid::into_arc to convert a Clothoid into a bounded arc:

use clothoid::Clothoid;
use path_traits::Path;

let c = Clothoid::new(2.0);
let arc = c.into_arc(4.0);
assert!((arc.length() - 4.0).abs() < 1e-10);

§Features

  • fresnel — enables high-precision Fresnel integral computation via the external fresnel crate. When disabled, uses an approximation based on auxiliary functions (Wilde 2009 / Abramowitz & Stegun).
  • optimizers (default) — enables both nelder-mead and cma-es solvers, plus the fit module.
  • nelder-mead — enables the Nelder-Mead simplex optimizer and the fit module.
  • cma-es — enables the CMA-ES optimizer and the fit module.
  • path-traits (default) — enables path_traits integration with ClothoidArc, LinearSegment, ClothoidPath, and Vec2.

Re-exports§

pub use fit::DefaultPlanner;nelder-mead or cma-es
pub use fit::Planner;nelder-mead or cma-es
pub use optimizer::PlanObjective;
pub use optimizer::SymmetryMode;
pub use optimizer::CmaEs;cma-es
pub use optimizer::NelderMead;nelder-mead
pub use optimizer::Optimizer;nelder-mead or cma-es
pub use path_traits_impls::ArcSegment;path-traits
pub use path_traits_impls::ClothoidArc;path-traits
pub use path_traits_impls::ClothoidPath;path-traits
pub use path_traits_impls::LinearSegment;path-traits
pub use path_traits_impls::Vec2;path-traits

Modules§

fitnelder-mead or cma-es
Incremental path fitting using clothoid segments.
optimizer
Path evaluation and optimization utilities for clothoid fitting.
path_traits_implspath-traits
Implementation of path_traits for clothoid types.

Structs§

Clothoid
A Clothoid (Euler spiral) curve.
Point2
A point in 2D Cartesian space.