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: StringImplementations§
Source§impl<T> Transform<T>where
T: TimePoint,
impl<T> Transform<T>where
T: TimePoint,
Sourcepub fn interpolate(
from: &Transform<T>,
to: &Transform<T>,
timestamp: T,
) -> Result<Transform<T>, TransformError>
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);Sourcepub fn identity() -> Self
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);Sourcepub fn inverse(&self) -> Result<Self, TransformError>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.