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, ×).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
impl RotationSpline
Sourcepub fn new(rotations: &[Rotation], times: &[f64]) -> SpatialResult<Self>
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 rotationstimes- 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, ×).unwrap();Sourcepub fn set_interpolation_type(&mut self, _interptype: &str) -> SpatialResult<()>
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, ×).unwrap();
// Set the interpolation type to cubic (natural cubic spline)
spline.set_interpolation_type("cubic").unwrap();Sourcepub fn interpolate(&self, t: f64) -> Rotation
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, ×).unwrap();
// Interpolate at t=0.5 (halfway between the first two rotations)
let rot_half = spline.interpolate(0.5);Sourcepub fn times(&self) -> &Vec<f64>
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, ×).unwrap();
let retrieved_times = spline.times();
assert_eq!(retrieved_times, &vec![0.0, 1.0]);Sourcepub fn rotations(&self) -> &Vec<Rotation>
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, ×).unwrap();
let retrieved_rotations = spline.rotations();
assert_eq!(retrieved_rotations.len(), 2);Sourcepub fn sample(&self, n: usize) -> (Vec<f64>, Vec<Rotation>)
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, ×).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);Sourcepub fn from_key_rotations(
_key_rots: &[Rotation],
keytimes: &[f64],
) -> SpatialResult<Self>
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 rotationskeytimes- 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();Sourcepub fn interpolation_type(&self) -> &str
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, ×).unwrap();
assert_eq!(spline.interpolation_type(), "slerp");Sourcepub fn angular_velocity(&self, t: f64) -> SpatialResult<Array1<f64>>
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, ×).unwrap();
// Calculate angular velocity at t=0.5
let velocity = spline.angular_velocity(0.5);
// Should be approximately [0, 0, PI]Sourcepub fn angular_acceleration(&self, t: f64) -> Array1<f64>
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, ×).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
impl Clone for RotationSpline
Source§fn clone(&self) -> RotationSpline
fn clone(&self) -> RotationSpline
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RotationSpline
impl RefUnwindSafe for RotationSpline
impl Send for RotationSpline
impl Sync for RotationSpline
impl Unpin for RotationSpline
impl UnwindSafe for RotationSpline
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
§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)
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>
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>
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>
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.