Struct bevy_math::cubic_splines::CubicCurve
source · pub struct CubicCurve<P: Point> { /* private fields */ }
Expand description
A collection of CubicSegment
s chained into a curve.
Use any struct that implements the CubicGenerator
trait to create a new curve, such as
CubicBezier
.
Implementations§
source§impl<P: Point> CubicCurve<P>
impl<P: Point> CubicCurve<P>
sourcepub fn position(&self, t: f32) -> P
pub fn position(&self, t: f32) -> P
Compute the position of a point on the cubic curve at the parametric value t
.
Note that t
varies from 0..=(n_points - 3)
.
sourcepub fn velocity(&self, t: f32) -> P
pub fn velocity(&self, t: f32) -> P
Compute the first derivative with respect to t at t
. This is the instantaneous velocity of
a point on the cubic curve at t
.
Note that t
varies from 0..=(n_points - 3)
.
sourcepub fn acceleration(&self, t: f32) -> P
pub fn acceleration(&self, t: f32) -> P
Compute the second derivative with respect to t at t
. This is the instantaneous
acceleration of a point on the cubic curve at t
.
Note that t
varies from 0..=(n_points - 3)
.
sourcepub fn iter_samples<'a, 'b: 'a>(
&'b self,
subdivisions: usize,
sample_function: impl FnMut(&Self, f32) -> P + 'a
) -> impl Iterator<Item = P> + 'a
pub fn iter_samples<'a, 'b: 'a>( &'b self, subdivisions: usize, sample_function: impl FnMut(&Self, f32) -> P + 'a ) -> impl Iterator<Item = P> + 'a
A flexible iterator used to sample curves with arbitrary functions.
This splits the curve into subdivisions
of evenly spaced t
values across the
length of the curve from start (t = 0) to end (t = n), where n = self.segment_count()
,
returning an iterator evaluating the curve with the supplied sample_function
at each t
.
For subdivisions = 2
, this will split the curve into two lines, or three points, and
return an iterator with 3 items, the three points, one at the start, middle, and end.
sourcepub fn segments(&self) -> &[CubicSegment<P>]
pub fn segments(&self) -> &[CubicSegment<P>]
The list of segments contained in this CubicCurve
.
This spline’s global t
value is equal to how many segments it has.
All method accepting t
on CubicCurve
depends on the global t
.
When sampling over the entire curve, you should either use one of the
iter_*
methods or account for the segment count using curve.segments().len()
.
sourcepub fn iter_positions(
&self,
subdivisions: usize
) -> impl Iterator<Item = P> + '_
pub fn iter_positions( &self, subdivisions: usize ) -> impl Iterator<Item = P> + '_
Iterate over the curve split into subdivisions
, sampling the position at each step.
sourcepub fn iter_velocities(
&self,
subdivisions: usize
) -> impl Iterator<Item = P> + '_
pub fn iter_velocities( &self, subdivisions: usize ) -> impl Iterator<Item = P> + '_
Iterate over the curve split into subdivisions
, sampling the velocity at each step.
sourcepub fn iter_accelerations(
&self,
subdivisions: usize
) -> impl Iterator<Item = P> + '_
pub fn iter_accelerations( &self, subdivisions: usize ) -> impl Iterator<Item = P> + '_
Iterate over the curve split into subdivisions
, sampling the acceleration at each step.
Trait Implementations§
source§impl<P: Clone + Point> Clone for CubicCurve<P>
impl<P: Clone + Point> Clone for CubicCurve<P>
source§fn clone(&self) -> CubicCurve<P>
fn clone(&self) -> CubicCurve<P>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<P: PartialEq + Point> PartialEq for CubicCurve<P>
impl<P: PartialEq + Point> PartialEq for CubicCurve<P>
source§fn eq(&self, other: &CubicCurve<P>) -> bool
fn eq(&self, other: &CubicCurve<P>) -> bool
self
and other
values to be equal, and is used
by ==
.