#[repr(C)]
pub struct Rotation3D<T, Src, Dst> { pub i: T, pub j: T, pub k: T, pub r: T, /* private fields */ }
Expand description

A transform that can represent rotations in 3d, represented as a quaternion.

Most methods expect the quaternion to be normalized. When in doubt, use unit_quaternion instead of quaternion to create a rotation as the former will ensure that its result is normalized.

Some people use the x, y, z, w (or w, x, y, z) notations. The equivalence is as follows: x -> i, y -> j, z -> k, w -> r. The memory layout of this type corresponds to the x, y, z, w notation

Fields

i: T

Component multiplied by the imaginary number i.

j: T

Component multiplied by the imaginary number j.

k: T

Component multiplied by the imaginary number k.

r: T

The real part.

Implementations

Creates a rotation around from a quaternion representation.

The parameters are a, b, c and r compose the quaternion a*i + b*j + c*k + r where a, b and c describe the vector part and the last parameter r is the real part.

The resulting quaternion is not necessarily normalized. See unit_quaternion.

Creates the identity rotation.

Returns the vector part (i, j, k) of this quaternion.

Cast the unit, preserving the numeric value.

Example
enum Local {}
enum World {}

enum Local2 {}
enum World2 {}

let to_world: Rotation3D<_, Local, World> = Rotation3D::quaternion(1, 2, 3, 4);

assert_eq!(to_world.i, to_world.cast_unit::<Local2, World2>().i);
assert_eq!(to_world.j, to_world.cast_unit::<Local2, World2>().j);
assert_eq!(to_world.k, to_world.cast_unit::<Local2, World2>().k);
assert_eq!(to_world.r, to_world.cast_unit::<Local2, World2>().r);

Drop the units, preserving only the numeric value.

Example
enum Local {}
enum World {}

let to_world: Rotation3D<_, Local, World> = Rotation3D::quaternion(1, 2, 3, 4);

assert_eq!(to_world.i, to_world.to_untyped().i);
assert_eq!(to_world.j, to_world.to_untyped().j);
assert_eq!(to_world.k, to_world.to_untyped().k);
assert_eq!(to_world.r, to_world.to_untyped().r);

Tag a unitless value with units.

Example
use euclid::UnknownUnit;
enum Local {}
enum World {}

let rot: Rotation3D<_, UnknownUnit, UnknownUnit> = Rotation3D::quaternion(1, 2, 3, 4);

assert_eq!(rot.i, Rotation3D::<_, Local, World>::from_untyped(&rot).i);
assert_eq!(rot.j, Rotation3D::<_, Local, World>::from_untyped(&rot).j);
assert_eq!(rot.k, Rotation3D::<_, Local, World>::from_untyped(&rot).k);
assert_eq!(rot.r, Rotation3D::<_, Local, World>::from_untyped(&rot).r);

Creates a rotation around from a quaternion representation and normalizes it.

The parameters are a, b, c and r compose the quaternion a*i + b*j + c*k + r before normalization, where a, b and c describe the vector part and the last parameter r is the real part.

Creates a rotation around a given axis.

Creates a rotation around the x axis.

Creates a rotation around the y axis.

Creates a rotation around the z axis.

Creates a rotation from Euler angles.

The rotations are applied in roll then pitch then yaw order.

  • Roll (also called bank) is a rotation around the x axis.
  • Pitch (also called bearing) is a rotation around the y axis.
  • Yaw (also called heading) is a rotation around the z axis.

Returns the inverse of this rotation.

Computes the norm of this quaternion.

Computes the squared norm of this quaternion.

Returns a unit quaternion from this one.

Returns true if norm of this quaternion is (approximately) one.

Spherical linear interpolation between this rotation and another rotation.

t is expected to be between zero and one.

Basic Linear interpolation between this rotation and another rotation.

Returns the given 3d point transformed by this rotation.

The input point must be use the unit Src, and the returned point has the unit Dst.

Returns the given 2d point transformed by this rotation then projected on the xy plane.

The input point must be use the unit Src, and the returned point has the unit Dst.

Returns the given 3d vector transformed by this rotation.

The input vector must be use the unit Src, and the returned point has the unit Dst.

Returns the given 2d vector transformed by this rotation then projected on the xy plane.

The input vector must be use the unit Src, and the returned point has the unit Dst.

Returns the matrix representation of this rotation.

Returns a rotation representing this rotation followed by the other rotation.

Trait Implementations

Default epsilon value

Returns true is this object is approximately equal to the other one, using a provided epsilon value. Read more

Returns true is this object is approximately equal to the other one, using the approx_epsilon() epsilon value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.