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: StringImplementations§
Source§impl Transform
impl Transform
Sourcepub fn interpolate(
from: Transform,
to: Transform,
timestamp: Timestamp,
) -> Result<Transform, TransformError>
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);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.
§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);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::identity();
let result = (transform * inverse).unwrap();
assert_eq!(result.translation, identity.translation);
assert_eq!(result.rotation, identity.rotation);Trait Implementations§
impl Eq for Transform
Auto Trait Implementations§
impl Freeze for Transform
impl RefUnwindSafe for Transform
impl Send for Transform
impl Sync for Transform
impl Unpin for Transform
impl UnwindSafe for Transform
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.