Slerp

Struct Slerp 

Source
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

Source

pub fn new(start: Rotation, end: Rotation) -> SpatialResult<Self>

Create a new Slerp interpolator between two rotations

§Arguments
  • start - The starting rotation
  • end - 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();
Source

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);
Source

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§

Source§

impl Clone for Slerp

Source§

fn clone(&self) -> Slerp

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Slerp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V