RigidTransform

Struct RigidTransform 

Source
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

Source

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 component
  • translation - 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();
Source

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();
Source

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 translation
Source

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();
Source

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();
Source

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)
Source

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());
Source

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();
Source

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]
Source

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]
Source

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]
Source

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

Source§

fn clone(&self) -> RigidTransform

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 Debug for RigidTransform

Source§

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

Formats the value using the given formatter. Read more

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V