pub struct Trajectory { /* private fields */ }Expand description
A time-parameterized trajectory with sampling support.
Stores a sequence of TrajectoryPoints and provides methods for
sampling the trajectory at arbitrary times with interpolation.
§Sampling
Use sample to get the trajectory state at any time.
The method interpolates between stored points for smooth tracking.
Implementations§
Source§impl Trajectory
impl Trajectory
Sourcepub const fn from_points(points: Vec<TrajectoryPoint>) -> Self
pub const fn from_points(points: Vec<TrajectoryPoint>) -> Self
Creates a trajectory from time-ordered points.
§Arguments
points- Vector of trajectory points, must be in ascending time order
Sourcepub fn points(&self) -> &[TrajectoryPoint]
pub fn points(&self) -> &[TrajectoryPoint]
Returns a read-only view of trajectory points.
Sourcepub fn total_time(&self) -> Option<QTime>
pub fn total_time(&self) -> Option<QTime>
Returns the total trajectory duration.
§Returns
The time of the last point, or None if the trajectory is empty.
Sourcepub fn push(&mut self, point: TrajectoryPoint)
pub fn push(&mut self, point: TrajectoryPoint)
Adds a point to the end of the trajectory.
Points should be added in ascending time order.
Sourcepub fn sample(&self, time: QTime) -> Option<TrajectoryPoint>
pub fn sample(&self, time: QTime) -> Option<TrajectoryPoint>
Samples the trajectory at the given time with interpolation.
Returns the interpolated trajectory state at the specified time. If the time is outside the trajectory bounds, the nearest endpoint is returned.
§Arguments
time- Time from trajectory start
§Returns
The interpolated trajectory point, or None if the trajectory is empty.
§Interpolation
Position and heading are linearly interpolated. Heading interpolation takes the shortest angular path.
Sourcepub fn from_cubic_bezier(
p0: Vector2<f64>,
p1: Vector2<f64>,
p2: Vector2<f64>,
p3: Vector2<f64>,
total_time: QTime,
samples: usize,
linear_velocity: f64,
) -> Self
pub fn from_cubic_bezier( p0: Vector2<f64>, p1: Vector2<f64>, p2: Vector2<f64>, p3: Vector2<f64>, total_time: QTime, samples: usize, linear_velocity: f64, ) -> Self
Creates a trajectory by sampling a cubic Bézier curve.
Generates a trajectory by sampling a cubic Bezier spline at regular intervals. The heading is derived from the curve tangent, and angular velocity is estimated from heading changes between samples.
§Arguments
p0- Start point (meters)p1- First control point (meters)p2- Second control point (meters)p3- End point (meters)total_time- Total trajectory durationsamples- Number of points to generatelinear_velocity- Constant linear velocity for all points (m/s)
§Returns
A trajectory with samples points along the Bézier curve.
§Example
// S-curve trajectory
let traj = Trajectory::from_cubic_bezier(
Vector2::new(0.0, 0.0),
Vector2::new(1.0, 0.0),
Vector2::new(0.0, 1.0),
Vector2::new(1.0, 1.0),
QTime::from_sec(2.0),
50,
0.8,
);Trait Implementations§
Source§impl Clone for Trajectory
impl Clone for Trajectory
Source§fn clone(&self) -> Trajectory
fn clone(&self) -> Trajectory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Trajectory
impl Debug for Trajectory
Auto Trait Implementations§
impl Freeze for Trajectory
impl RefUnwindSafe for Trajectory
impl Send for Trajectory
impl Sync for Trajectory
impl Unpin for Trajectory
impl UnsafeUnpin for Trajectory
impl UnwindSafe for Trajectory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.