RotationSpline

Struct RotationSpline 

Source
pub struct RotationSpline { /* private fields */ }
Expand description

RotationSpline provides smooth interpolation between multiple rotations.

A rotation spline allows for smooth interpolation between a sequence of rotations, creating a continuous curve in rotation space. It can be used to create smooth camera paths, character animations, or any other application requiring smooth rotation transitions.

§Examples

use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

// Create some rotations
let rotations = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz").unwrap(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
];

// Create times at which these rotations occur
let times = vec![0.0, 0.5, 1.0];

// Create a rotation spline
let spline = RotationSpline::new(&rotations, &times).unwrap();

// Get the interpolated rotation at t=0.25 (between the first two rotations)
let rot_25 = spline.interpolate(0.25);

// Get the interpolated rotation at t=0.75 (between the second two rotations)
let rot_75 = spline.interpolate(0.75);

Implementations§

Source§

impl RotationSpline

Source

pub fn new(rotations: &[Rotation], times: &[f64]) -> SpatialResult<Self>

Create a new rotation spline from a sequence of rotations and times

§Arguments
  • rotations - A sequence of rotations
  • times - The times at which these rotations occur
§Returns

A SpatialResult containing the RotationSpline if valid, or an error if invalid

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

let rotations = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz").unwrap(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
];
let times = vec![0.0, 1.0, 2.0];
let spline = RotationSpline::new(&rotations, &times).unwrap();
Source

pub fn set_interpolation_type(&mut self, _interptype: &str) -> SpatialResult<()>

Set the interpolation type for the rotation spline

§Arguments
  • _interptype - The interpolation type (“slerp” or “cubic”)
§Returns

A SpatialResult containing nothing if successful, or an error if the interpolation type is invalid

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

let rotations = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz").unwrap(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
];
let times = vec![0.0, 1.0, 2.0];
let mut spline = RotationSpline::new(&rotations, &times).unwrap();

// Set the interpolation type to cubic (natural cubic spline)
spline.set_interpolation_type("cubic").unwrap();
Source

pub fn interpolate(&self, t: f64) -> Rotation

Interpolate the rotation spline at a given time

§Arguments
  • t - The time at which to interpolate
§Returns

The interpolated rotation

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

let rotations = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz").unwrap(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
];
let times = vec![0.0, 1.0, 2.0];
let spline = RotationSpline::new(&rotations, &times).unwrap();

// Interpolate at t=0.5 (halfway between the first two rotations)
let rot_half = spline.interpolate(0.5);
Source

pub fn times(&self) -> &Vec<f64>

Get the times at which the rotations are defined

§Returns

A reference to the times vector

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;

let rotations = vec![
    Rotation::identity(),
    Rotation::identity(),
];
let times = vec![0.0, 1.0];
let spline = RotationSpline::new(&rotations, &times).unwrap();

let retrieved_times = spline.times();
assert_eq!(retrieved_times, &vec![0.0, 1.0]);
Source

pub fn rotations(&self) -> &Vec<Rotation>

Get the rotations that define the spline

§Returns

A reference to the rotations vector

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;

let rotations = vec![
    Rotation::identity(),
    Rotation::identity(),
];
let times = vec![0.0, 1.0];
let spline = RotationSpline::new(&rotations, &times).unwrap();

let retrieved_rotations = spline.rotations();
assert_eq!(retrieved_rotations.len(), 2);
Source

pub fn sample(&self, n: usize) -> (Vec<f64>, Vec<Rotation>)

Generate evenly spaced samples from the rotation spline

§Arguments
  • n - The number of samples to generate
§Returns

A vector of sampled rotations and the corresponding times

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

let rotations = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
];
let times = vec![0.0, 1.0];
let spline = RotationSpline::new(&rotations, &times).unwrap();

// Generate 5 samples from the spline
let (sample_times, sample_rotations) = spline.sample(5);
assert_eq!(sample_times.len(), 5);
assert_eq!(sample_rotations.len(), 5);
Source

pub fn from_key_rotations( _key_rots: &[Rotation], keytimes: &[f64], ) -> SpatialResult<Self>

Create a new rotation spline from key rotations at specific times

This is equivalent to the regular constructor but with a more explicit name.

§Arguments
  • key_rots - The key rotations
  • keytimes - The times at which these key rotations occur
§Returns

A SpatialResult containing the RotationSpline if valid, or an error if invalid

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

let key_rots = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz").unwrap(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
];
let keytimes = vec![0.0, 1.0, 2.0];

let spline = RotationSpline::from_key_rotations(&key_rots, &keytimes).unwrap();
Source

pub fn interpolation_type(&self) -> &str

Get the current interpolation type

§Returns

The current interpolation type (“slerp” or “cubic”)

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;

let rotations = vec![
    Rotation::identity(),
    Rotation::identity(),
];
let times = vec![0.0, 1.0];
let spline = RotationSpline::new(&rotations, &times).unwrap();

assert_eq!(spline.interpolation_type(), "slerp");
Source

pub fn angular_velocity(&self, t: f64) -> SpatialResult<Array1<f64>>

Calculate the angular velocity at a specific time

§Arguments
  • t - The time at which to calculate the angular velocity
§Returns

The angular velocity as a 3-element array

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

let rotations = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
];
let times = vec![0.0, 1.0];
let spline = RotationSpline::new(&rotations, &times).unwrap();

// Calculate angular velocity at t=0.5
let velocity = spline.angular_velocity(0.5);
// Should be approximately [0, 0, PI]
Source

pub fn angular_acceleration(&self, t: f64) -> Array1<f64>

Calculate the angular acceleration at a specific time

§Arguments
  • t - The time at which to calculate the angular acceleration
§Returns

The angular acceleration as a 3-element array

§Examples
use scirs2_spatial::transform::{Rotation, RotationSpline};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;

let rotations = vec![
    Rotation::identity(),
    Rotation::from_euler(&array![0.0, 0.0, PI].view(), "xyz").unwrap(),
    Rotation::identity(),
];
let times = vec![0.0, 1.0, 2.0];
let mut spline = RotationSpline::new(&rotations, &times).unwrap();

// Set to cubic interpolation for non-zero acceleration
spline.set_interpolation_type("cubic").unwrap();

// Calculate angular acceleration at t=0.5
let acceleration = spline.angular_acceleration(0.5);

Trait Implementations§

Source§

impl Clone for RotationSpline

Source§

fn clone(&self) -> RotationSpline

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RotationSpline

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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.
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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