# Quaternion

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-media3d/struct-quaternion/

**struct** · [`ferroui-media3d`](/docs/0.5.0/api/ferroui-media3d/) · v0.5.0

```rust
struct Quaternion
```

A rotation in 3D space, with double-precision components (WPF's
`System.Windows.Media.Media3D.Quaternion`): `(x, y, z)` is the axis scaled by the sine of half
the angle, `w` the cosine of half the angle.

This is the quaternion of the 3D scene model, apart from the single-precision
`ferroui_base::numerics::Quaternion` of the numerics library. The default value is
`Quaternion::IDENTITY`, as in WPF.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L20)

## Members

- [`x`](#struct_field-x)
- [`y`](#struct_field-y)
- [`z`](#struct_field-z)
- [`w`](#struct_field-w)
- [`IDENTITY`](#assoc_const-identity)
- [`new`](#function-new)
- [`from_axis_angle`](#function-from_axis_angle)
- [`is_identity`](#function-is_identity)
- [`is_normalized`](#function-is_normalized)
- [`axis`](#function-axis)
- [`angle`](#function-angle)
- [`conjugate`](#function-conjugate)
- [`invert`](#function-invert)
- [`normalize`](#function-normalize)
- [`slerp`](#function-slerp)
- [`slerp_with_path`](#function-slerp_with_path)
- [`parse`](#function-parse)

<a id="struct_field-x"></a>

### x

```rust
x: f64
```

The X component.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L22)

<a id="struct_field-y"></a>

### y

```rust
y: f64
```

The Y component.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L24)

<a id="struct_field-z"></a>

### z

```rust
z: f64
```

The Z component.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L26)

<a id="struct_field-w"></a>

### w

```rust
w: f64
```

The W component.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L28)

<a id="assoc_const-identity"></a>

### IDENTITY

```rust
const IDENTITY: Quaternion
```

The rotation by no angle (WPF's `Quaternion.Identity`): `(0, 0, 0, 1)`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L33)

<a id="function-new"></a>

### new

```rust
const fn new(x: f64, y: f64, z: f64, w: f64) -> Self
```

A quaternion with the given components.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L37)

<a id="function-from_axis_angle"></a>

### from_axis_angle

```rust
fn from_axis_angle(axis_of_rotation: Vector3D, angle_in_degrees: f64) -> Result<Self, QuaternionError>
```

The rotation about the axis by the angle in degrees, counterclockwise when the axis points
at the viewer. The angle is taken modulo 360 before it is converted to radians, as WPF does;
`QuaternionError::ZeroAxis` when the axis is the zero vector.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L44)

<a id="function-is_identity"></a>

### is_identity

```rust
fn is_identity(self: &Self) -> bool
```

Whether this is the identity: `(0, 0, 0, 1)`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L56)

<a id="function-is_normalized"></a>

### is_normalized

```rust
fn is_normalized(self: &Self) -> bool
```

Whether the quaternion has unit length, within ten machine epsilons of its squared norm.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L62)

<a id="function-axis"></a>

### axis

```rust
fn axis(self: &Self) -> Vector3D
```

The axis of the rotation, a unit vector; `(0, 1, 0)` when the axis is undetermined (the
identity, and every quaternion whose `x`, `y` and `z` are zero).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L68)

<a id="function-angle"></a>

### angle

```rust
fn angle(self: &Self) -> f64
```

The angle of the rotation in degrees, from 0 to 360, for a quaternion of any length.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L78)

<a id="function-conjugate"></a>

### conjugate

```rust
fn conjugate(self: &mut Self)
```

Replaces the quaternion by its conjugate: the axis reversed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L93)

<a id="function-invert"></a>

### invert

```rust
fn invert(self: &mut Self)
```

Replaces the quaternion by its inverse: the conjugate divided by the squared norm. The zero
quaternion becomes `NaN` components, as in WPF.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L101)

<a id="function-normalize"></a>

### normalize

```rust
fn normalize(self: &mut Self)
```

Scales the quaternion to unit length. When the squared norm overflows, the components are
first divided by the largest of their magnitudes.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L112)

<a id="function-slerp"></a>

### slerp

```rust
fn slerp(from: Quaternion, to: Quaternion, t: f64) -> Quaternion
```

The spherical linear interpolation from `from` to `to` at `t` (0 is `from`, 1 is `to`),
along the shorter arc.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L125)

<a id="function-slerp_with_path"></a>

### slerp_with_path

```rust
fn slerp_with_path(from: Quaternion, to: Quaternion, t: f64, use_shortest_path: bool) -> Quaternion
```

The spherical linear interpolation from `from` to `to` at `t` (WPF's `Slerp` with
`useShortestPath`): along the shorter arc when `use_shortest_path` is true (`to` is negated
when the two are more than 90 degrees apart in four dimensions), else along the arc between
the quaternions as given.

The inputs need not have unit length: the direction is interpolated between the unit
quaternions, and the length of the result is interpolated geometrically between the lengths
of the inputs. Quaternions closer than a cosine of `1 - 1e-6` are interpolated linearly;
opposite quaternions turn about an arbitrary perpendicular.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L138)

<a id="function-parse"></a>

### parse

```rust
fn parse(text: &str) -> Result<Self, FormatError>
```

Parses the text form: `"Identity"`, or `"x,y,z,w"` (commas, white space or both between the
numbers) in the invariant culture.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Media3D/quaternion.rs#L197)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Default`
- `Add`
- `Sub`
- `Mul`
- `FromStr`
- `Display`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
