pub struct Slerp { /* private fields */ }Expand description
Slerp represents a spherical linear interpolation between two rotations.
Spherical linear interpolation provides smooth interpolation between two rotations along the shortest arc on the hypersphere of unit quaternions.
§Examples
use scirs2_spatial::transform::{Rotation, Slerp};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;
// Create two rotations to interpolate between
let rot1 = Rotation::from_euler(&array![0.0, 0.0, 0.0].view(), "xyz").unwrap();
let rot2 = Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz").unwrap();
// Create a Slerp interpolator
let slerp = Slerp::new(rot1, rot2).unwrap();
// Get the interpolated rotation at t=0.5 (halfway between rot1 and rot2)
let rot_half = slerp.interpolate(0.5);
// Apply the rotation to a point
let point = array![1.0, 0.0, 0.0];
let rotated = rot_half.apply(&point.view()).unwrap();
// Should be approximately [std::f64::consts::FRAC_1_SQRT_2, std::f64::consts::FRAC_1_SQRT_2, 0.0]Implementations§
Source§impl Slerp
impl Slerp
Sourcepub fn new(start: Rotation, end: Rotation) -> SpatialResult<Self>
pub fn new(start: Rotation, end: Rotation) -> SpatialResult<Self>
Create a new Slerp interpolator between two rotations
§Arguments
start- The starting rotationend- The ending rotation
§Returns
A SpatialResult containing the Slerp object if valid, or an error if invalid
§Examples
use scirs2_spatial::transform::{Rotation, Slerp};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;
let rot1 = Rotation::identity();
let rot2 = Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz").unwrap();
let slerp = Slerp::new(rot1, rot2).unwrap();Sourcepub fn interpolate(&self, t: f64) -> Rotation
pub fn interpolate(&self, t: f64) -> Rotation
Interpolate between the start and end rotations
§Arguments
t- The interpolation parameter (0.0 = start, 1.0 = end)
§Returns
The interpolated rotation
§Examples
use scirs2_spatial::transform::{Rotation, Slerp};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;
let rot1 = Rotation::identity();
let rot2 = Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap();
let slerp = Slerp::new(rot1, rot2).unwrap();
// Get rotation at t=0.25 (25% from rot1 to rot2)
let rot_25 = slerp.interpolate(0.25);
// Get rotation at t=0.5 (halfway)
let rot_50 = slerp.interpolate(0.5);
// Get rotation at t=0.75 (75% from rot1 to rot2)
let rot_75 = slerp.interpolate(0.75);Sourcepub fn times(n: usize) -> Vec<f64>
pub fn times(n: usize) -> Vec<f64>
Get times at which the interpolated rotations would have a constant angular velocity
§Arguments
n- The number of times to generate
§Returns
A vector of times between 0.0 and 1.0
§Examples
use scirs2_spatial::transform::{Rotation, Slerp};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;
let rot1 = Rotation::identity();
let rot2 = Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap();
let slerp = Slerp::new(rot1, rot2).unwrap();
// Get 5 times for constant angular velocity
let times = Slerp::times(5);
// Should be [0.0, 0.25, 0.5, 0.75, 1.0]Trait Implementations§
Auto Trait Implementations§
impl Freeze for Slerp
impl RefUnwindSafe for Slerp
impl Send for Slerp
impl Sync for Slerp
impl Unpin for Slerp
impl UnwindSafe for Slerp
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.