transforms::geometry::transform

Struct Transform

Source
pub struct Transform {
    pub translation: Vector3,
    pub rotation: Quaternion,
    pub timestamp: Timestamp,
    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};

// Create an identity transform
let identity = Transform::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: Timestamp§parent: String§child: String

Implementations§

Source§

impl Transform

Source

pub fn interpolate( from: Transform, to: Transform, timestamp: Timestamp, ) -> Result<Transform, 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 { nanoseconds: 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 {
        nanoseconds: 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 {
        nanoseconds: 1_000_000_000,
    },
    parent: "a".into(),
    child: "b".into(),
};
let timestamp = Timestamp {
    nanoseconds: 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.

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

let identity = Transform::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 { nanoseconds: 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::identity();
let result = (transform * inverse).unwrap();
assert_eq!(result.translation, identity.translation);
assert_eq!(result.rotation, identity.rotation);

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a copy 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 Transform

Source§

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

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

impl Mul for Transform

Source§

type Output = Result<Transform, TransformError>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl PartialEq for Transform

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 Eq for Transform

Auto Trait Implementations§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.