Skip to main content

Transform

Struct Transform 

Source
pub struct Transform<T = Timestamp>
where T: TimePoint,
{ pub translation: Vector3, pub rotation: Quaternion, pub timestamp: T, pub parent: String, pub child: String, }
Expand description

Represents a 3D transformation with translation, rotation, and timestamp.

The Transform struct is used to represent a transformation in 3D space, including translation, rotation, and associated metadata such as timestamps and frame identifiers.

§Examples

use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
};

// Create an identity transform
let identity = Transform::<Timestamp>::identity();

assert_eq!(
    identity.translation,
    Vector3 {
        x: 0.0,
        y: 0.0,
        z: 0.0
    }
);

assert_eq!(
    identity.rotation,
    Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0
    }
);

Fields§

§translation: Vector3§rotation: Quaternion§timestamp: T§parent: String§child: String

Implementations§

Source§

impl<T> Transform<T>
where T: TimePoint,

Source

pub fn interpolate( from: &Transform<T>, to: &Transform<T>, timestamp: T, ) -> Result<Transform<T>, TransformError>

Interpolates between two transforms at a given timestamp.

Returns a new Transform that is the interpolation between from and to at the specified timestamp.

§Errors

Returns TransformError::TimestampMismatch if the timestamp is outside the range of from and to. Returns TransformError::IncompatibleFrames if the frames do not match.

§Examples
use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
};

let from = Transform {
    translation: Vector3 {
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: Timestamp { t: 0 },
    parent: "a".into(),
    child: "b".into(),
};
let to = Transform {
    translation: Vector3 {
        x: 2.0,
        y: 2.0,
        z: 2.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: Timestamp { t: 2_000_000_000 },
    parent: "a".into(),
    child: "b".into(),
};
let result = Transform {
    translation: Vector3 {
        x: 1.0,
        y: 1.0,
        z: 1.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: Timestamp { t: 1_000_000_000 },
    parent: "a".into(),
    child: "b".into(),
};
let timestamp = Timestamp { t: 1_000_000_000 };

let interpolated = Transform::interpolate(&from, &to, timestamp).unwrap();
assert_eq!(result, interpolated);
Source

pub fn identity() -> Self

Returns the identity transform.

The identity transform has no translation or rotation and is often used as a neutral element in transformations.

The timestamp is set to the static timestamp value for the active timestamp type (Timestamp::zero() by default).

§Examples
use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
};

let identity = Transform::<Timestamp>::identity();
let transform = Transform {
    translation: Vector3 {
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: Timestamp { t: 0 },
    parent: "".into(),
    child: "".into(),
};

assert_eq!(identity, transform);
Source

pub fn inverse(&self) -> Result<Self, TransformError>

Computes the inverse of the transform.

Returns a new Transform that is the inverse of the current transform.

§Examples
use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
};

// Create a transform with specific translation and rotation
let transform = Transform {
    translation: Vector3 {
        x: 1.0,
        y: 2.0,
        z: 3.0,
    },
    rotation: Quaternion {
        w: 0.0,
        x: 1.0,
        y: 0.0,
        z: 0.0,
    }
    .normalize()
    .unwrap(),
    timestamp: Timestamp::zero(),
    parent: "a".into(),
    child: "b".into(),
};

// Compute its inverse
let inverse = transform.inverse().unwrap();

// Verify that the inverse has swapped frames
assert_eq!(inverse.parent, "b");
assert_eq!(inverse.child, "a");

// Verify that applying the inverse transformation results in the identity
let identity = Transform::<Timestamp>::identity();
let result = (transform * inverse).unwrap();
assert_eq!(result.translation, identity.translation);
assert_eq!(result.rotation, identity.rotation);
§Errors

This function returns a TransformError if:

  • The quaternion normalization fails, resulting in a QuaternionError.

Trait Implementations§

Source§

impl<T> Clone for Transform<T>
where T: TimePoint + Clone,

Source§

fn clone(&self) -> Transform<T>

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<T> Debug for Transform<T>
where T: TimePoint + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Mul for Transform<T>
where T: TimePoint,

Source§

type Output = Result<Transform<T>, TransformError>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Transform<T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> PartialEq for Transform<T>
where T: TimePoint,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Eq for Transform<T>
where T: TimePoint,

Auto Trait Implementations§

§

impl<T> Freeze for Transform<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Transform<T>
where T: RefUnwindSafe,

§

impl<T> Send for Transform<T>
where T: Send,

§

impl<T> Sync for Transform<T>
where T: Sync,

§

impl<T> Unpin for Transform<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Transform<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Transform<T>
where T: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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.