pub struct RigidTransform { /* private fields */ }Expand description
RigidTransform represents a rigid transformation in 3D space.
A rigid transformation is a combination of a rotation and a translation. It preserves the distance between any two points and the orientation of objects.
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;
// Create a rotation around Z and a translation
let rotation = Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz")?;
let translation = array![1.0, 2.0, 3.0];
// Create a rigid transform from rotation and translation
let transform = RigidTransform::from_rotation_and_translation(rotation, &translation.view())?;
// Apply the transform to a point
let point = array![0.0, 0.0, 0.0];
let transformed = transform.apply(&point.view());
// Should be [1.0, 2.0, 3.0] (just the translation for the origin)
// Another point
let point2 = array![1.0, 0.0, 0.0];
let transformed2 = transform.apply(&point2.view());
// Should be [1.0, 3.0, 3.0] (rotated then translated)Implementations§
Source§impl RigidTransform
impl RigidTransform
Sourcepub fn from_rotation_and_translation(
rotation: Rotation,
translation: &ArrayView1<'_, f64>,
) -> SpatialResult<Self>
pub fn from_rotation_and_translation( rotation: Rotation, translation: &ArrayView1<'_, f64>, ) -> SpatialResult<Self>
Create a new rigid transform from a rotation and translation
§Arguments
rotation- The rotation componenttranslation- The translation vector (3D)
§Returns
A SpatialResult containing the rigid transform if valid, or an error if invalid
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
let rotation = Rotation::identity();
let translation = array![1.0, 2.0, 3.0];
let transform = RigidTransform::from_rotation_and_translation(rotation, &translation.view()).unwrap();Sourcepub fn from_matrix(matrix: &ArrayView2<'_, f64>) -> SpatialResult<Self>
pub fn from_matrix(matrix: &ArrayView2<'_, f64>) -> SpatialResult<Self>
Create a rigid transform from a 4x4 transformation matrix
§Arguments
matrix- A 4x4 transformation matrix in homogeneous coordinates
§Returns
A SpatialResult containing the rigid transform if valid, or an error if invalid
§Examples
use scirs2_spatial::transform::RigidTransform;
use scirs2_core::ndarray::array;
// Create a transformation matrix for translation by [1, 2, 3]
let matrix = array![
[1.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 0.0, 2.0],
[0.0, 0.0, 1.0, 3.0],
[0.0, 0.0, 0.0, 1.0]
];
let transform = RigidTransform::from_matrix(&matrix.view()).unwrap();Sourcepub fn as_matrix(&self) -> Array2<f64>
pub fn as_matrix(&self) -> Array2<f64>
Convert the rigid transform to a 4x4 matrix in homogeneous coordinates
§Returns
A 4x4 transformation matrix
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
let rotation = Rotation::identity();
let translation = array![1.0, 2.0, 3.0];
let transform = RigidTransform::from_rotation_and_translation(rotation, &translation.view()).unwrap();
let matrix = transform.as_matrix();
// Should be a 4x4 identity matrix with the last column containing the translationSourcepub fn rotation(&self) -> &Rotation
pub fn rotation(&self) -> &Rotation
Get the rotation component of the rigid transform
§Returns
The rotation component
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
let rotation = Rotation::identity();
let translation = array![1.0, 2.0, 3.0];
let transform = RigidTransform::from_rotation_and_translation(rotation.clone(), &translation.view()).unwrap();
let retrieved_rotation = transform.rotation();Sourcepub fn translation(&self) -> &Array1<f64>
pub fn translation(&self) -> &Array1<f64>
Get the translation component of the rigid transform
§Returns
The translation vector
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
let rotation = Rotation::identity();
let translation = array![1.0, 2.0, 3.0];
let transform = RigidTransform::from_rotation_and_translation(rotation, &translation.view()).unwrap();
let retrieved_translation = transform.translation();Sourcepub fn apply(&self, point: &ArrayView1<'_, f64>) -> SpatialResult<Array1<f64>>
pub fn apply(&self, point: &ArrayView1<'_, f64>) -> SpatialResult<Array1<f64>>
Apply the rigid transform to a point or vector
§Arguments
point- A 3D point or vector to transform
§Returns
The transformed point or vector
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;
let rotation = Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz")?;
let translation = array![1.0, 2.0, 3.0];
let transform = RigidTransform::from_rotation_and_translation(rotation, &translation.view())?;
let point = array![1.0, 0.0, 0.0];
let transformed = transform.apply(&point.view())?;
// Should be [1.0, 3.0, 3.0] (rotated then translated)Sourcepub fn apply_multiple(
&self,
points: &ArrayView2<'_, f64>,
) -> SpatialResult<Array2<f64>>
pub fn apply_multiple( &self, points: &ArrayView2<'_, f64>, ) -> SpatialResult<Array2<f64>>
Apply the rigid transform to multiple points
§Arguments
points- A 2D array of points (each row is a 3D point)
§Returns
A 2D array of transformed points
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
let rotation = Rotation::identity();
let translation = array![1.0, 2.0, 3.0];
let transform = RigidTransform::from_rotation_and_translation(rotation, &translation.view()).unwrap();
let points = array![[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]];
let transformed = transform.apply_multiple(&points.view());Sourcepub fn inv(&self) -> SpatialResult<RigidTransform>
pub fn inv(&self) -> SpatialResult<RigidTransform>
Get the inverse of the rigid transform
§Returns
A new RigidTransform that is the inverse of this one
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
let rotation = Rotation::identity();
let translation = array![1.0, 2.0, 3.0];
let transform = RigidTransform::from_rotation_and_translation(rotation, &translation.view()).unwrap();
let inverse = transform.inv();Sourcepub fn compose(&self, other: &RigidTransform) -> SpatialResult<RigidTransform>
pub fn compose(&self, other: &RigidTransform) -> SpatialResult<RigidTransform>
Compose this rigid transform with another (apply the other transform after this one)
§Arguments
other- The other rigid transform to combine with
§Returns
A new RigidTransform that represents the composition
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
let t1 = RigidTransform::from_rotation_and_translation(
Rotation::identity(),
&array![1.0, 0.0, 0.0].view()
).unwrap();
let t2 = RigidTransform::from_rotation_and_translation(
Rotation::identity(),
&array![0.0, 1.0, 0.0].view()
).unwrap();
let combined = t1.compose(&t2);
// Should have a translation of [1.0, 1.0, 0.0]Sourcepub fn identity() -> RigidTransform
pub fn identity() -> RigidTransform
Create an identity rigid transform (no rotation, no translation)
§Returns
A new RigidTransform that represents identity
§Examples
use scirs2_spatial::transform::RigidTransform;
use scirs2_core::ndarray::array;
let identity = RigidTransform::identity();
let point = array![1.0, 2.0, 3.0];
let transformed = identity.apply(&point.view());
// Should still be [1.0, 2.0, 3.0]Sourcepub fn from_translation(
translation: &ArrayView1<'_, f64>,
) -> SpatialResult<RigidTransform>
pub fn from_translation( translation: &ArrayView1<'_, f64>, ) -> SpatialResult<RigidTransform>
Create a rigid transform that only has a translation component
§Arguments
translation- The translation vector
§Returns
A new RigidTransform with no rotation
§Examples
use scirs2_spatial::transform::RigidTransform;
use scirs2_core::ndarray::array;
let transform = RigidTransform::from_translation(&array![1.0, 2.0, 3.0].view()).unwrap();
let point = array![0.0, 0.0, 0.0];
let transformed = transform.apply(&point.view());
// Should be [1.0, 2.0, 3.0]Sourcepub fn from_rotation(rotation: Rotation) -> RigidTransform
pub fn from_rotation(rotation: Rotation) -> RigidTransform
Create a rigid transform that only has a rotation component
§Arguments
rotation- The rotation component
§Returns
A new RigidTransform with no translation
§Examples
use scirs2_spatial::transform::{Rotation, RigidTransform};
use scirs2_core::ndarray::array;
use std::f64::consts::PI;
let rotation = Rotation::from_euler(&array![0.0, 0.0, PI/2.0].view(), "xyz")?;
let transform = RigidTransform::from_rotation(rotation);
let point = array![1.0, 0.0, 0.0];
let transformed = transform.apply(&point.view())?;
// Should be [0.0, 1.0, 0.0]Trait Implementations§
Source§impl Clone for RigidTransform
impl Clone for RigidTransform
Source§fn clone(&self) -> RigidTransform
fn clone(&self) -> RigidTransform
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RigidTransform
impl RefUnwindSafe for RigidTransform
impl Send for RigidTransform
impl Sync for RigidTransform
impl Unpin for RigidTransform
impl UnwindSafe for RigidTransform
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<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.