| Flutter Impeller |

Public Member Functions | Public Attributes | List of all members
impeller::Quaternion Struct Reference

`#include <quaternion.h>`

## Public Member Functions
| Quaternion ()
| Quaternion (Scalar px, Scalar py, Scalar pz, Scalar pw)
| Quaternion (const Vector3 &axis, Scalar angle)
Scalar | Dot (const Quaternion &q) const
Scalar | Length () const
Quaternion | Normalize () const
Quaternion | Invert () const
Quaternion | Slerp (const Quaternion &to, double time) const
Quaternion | operator* (const Quaternion &o) const
Quaternion | operator* (Scalar scale) const
Vector3 | operator* (Vector3 vector) const
Quaternion | operator+ (const Quaternion &o) const
Quaternion | operator- (const Quaternion &o) const
bool | operator== (const Quaternion &o) const
bool | operator!= (const Quaternion &o) const

## Public Attributes
union {
struct {
Scalar x = 0.0
Scalar y = 0.0
Scalar z = 0.0
Scalar w = 1.0
} |
Scalar e [4]
}; |

## Detailed Description

Definition at line 14 of file quaternion.h.

## Constructor & Destructor Documentation

## ◆ Quaternion() [1/3]

impeller::Quaternion::Quaternion | ( |  | ) |
| inline

Definition at line 25 of file quaternion.h.

25 {}

## ◆ Quaternion() [2/3]

impeller::Quaternion::Quaternion | ( | Scalar | px,
|  | Scalar | py,
|  | Scalar | pz,
|  | Scalar | pw
| ) |  |
| inline

Definition at line 27 of file quaternion.h.

28 : x(px), y(py), z(pz), w(pw) {}
impeller::Quaternion::y
Scalar y
Definition: quaternion.h:18
impeller::Quaternion::z
Scalar z
Definition: quaternion.h:19
impeller::Quaternion::w
Scalar w
Definition: quaternion.h:20
impeller::Quaternion::x
Scalar x
Definition: quaternion.h:17

## ◆ Quaternion() [3/3]

impeller::Quaternion::Quaternion | ( | const Vector3 & | axis,
|  | Scalar | angle
| ) |  |
| inline

Definition at line 30 of file quaternion.h.

30 {
31 const auto sine = sin(angle * 0.5f);
32 x = sine * axis.x;
33 y = sine * axis.y;
34 z = sine * axis.z;
35 w = cos(angle * 0.5f);
36 }

References w, x, impeller::Vector3::x, y, impeller::Vector3::y, z, and impeller::Vector3::z.

## Member Function Documentation

## ◆ Dot()

Scalar impeller::Quaternion::Dot | ( | const Quaternion & | q | ) | const
| inline

Definition at line 38 of file quaternion.h.

38 {
39 return x * q.x + y * q.y + z * q.z + w * q.w;
40 }

References w, x, y, and z.

Referenced by Slerp().

## ◆ Invert()

Quaternion impeller::Quaternion::Invert | ( |  | ) | const
| inline

Definition at line 49 of file quaternion.h.

49 { return {-x, -y, -z, w}; }

References w, x, y, and z.

## ◆ Length()

Scalar impeller::Quaternion::Length | ( |  | ) | const
| inline

Definition at line 42 of file quaternion.h.

42 { return sqrt(x * x + y * y + z * z + w * w); }

References w, x, y, and z.

Referenced by Normalize().

## ◆ Normalize()

Quaternion impeller::Quaternion::Normalize | ( |  | ) | const
| inline

Definition at line 44 of file quaternion.h.

44 {
45 auto m = 1.0f / Length();
46 return {x * m, y * m, z * m, w * m};
47 }
impeller::Quaternion::Length
Scalar Length() const
Definition: quaternion.h:42

References Length(), w, x, y, and z.

Referenced by Slerp().

## ◆ operator!=()

bool impeller::Quaternion::operator!= | ( | const Quaternion & | o | ) | const
| inline

Definition at line 85 of file quaternion.h.

85 {
86 return x != o.x || y != o.y || z != o.z || w != o.w;
87 }

References w, x, y, and z.

## ◆ operator*() [1/3]

Quaternion impeller::Quaternion::operator* | ( | const Quaternion & | o | ) | const
| inline

Definition at line 53 of file quaternion.h.

53 {
54 return {
55 w * o.x + x * o.w + y * o.z - z * o.y,
56 w * o.y + y * o.w + z * o.x - x * o.z,
57 w * o.z + z * o.w + x * o.y - y * o.x,
58 w * o.w - x * o.x - y * o.y - z * o.z,
59 };
60 }

References w, x, y, and z.

## ◆ operator*() [2/3]

Quaternion impeller::Quaternion::operator* | ( | Scalar | scale | ) | const
| inline

Definition at line 62 of file quaternion.h.

62 {
63 return {scale * x, scale * y, scale * z, scale * w};
64 }
scale
const Scalar scale
Definition: stroke_path_geometry.cc:319

References scale, w, x, y, and z.

## ◆ operator*() [3/3]

Vector3 impeller::Quaternion::operator* | ( | Vector3 | vector | ) | const
| inline

Definition at line 66 of file quaternion.h.

66 {
67 Vector3 v(x, y, z);
68 return v * v.Dot(vector) * 2 + //
69 vector * (w * w - v.Dot(v)) + //
70 v.Cross(vector) * 2 * w;
71 }

References impeller::Vector3::Cross(), impeller::Vector3::Dot(), w, x, y, and z.

## ◆ operator+()

Quaternion impeller::Quaternion::operator+ | ( | const Quaternion & | o | ) | const
| inline

Definition at line 73 of file quaternion.h.

73 {
74 return {x + o.x, y + o.y, z + o.z, w + o.w};
75 }

References w, x, y, and z.

## ◆ operator-()

Quaternion impeller::Quaternion::operator- | ( | const Quaternion & | o | ) | const
| inline

Definition at line 77 of file quaternion.h.

77 {
78 return {x - o.x, y - o.y, z - o.z, w - o.w};
79 }

References w, x, y, and z.

## ◆ operator==()

bool impeller::Quaternion::operator== | ( | const Quaternion & | o | ) | const
| inline

Definition at line 81 of file quaternion.h.

81 {
82 return x == o.x && y == o.y && z == o.z && w == o.w;
83 }

References w, x, y, and z.

## ◆ Slerp()

Quaternion impeller::Quaternion::Slerp | ( | const Quaternion & | to,
|  | double | time
| ) |  | const

Definition at line 10 of file quaternion.cc.

10 {
11 double cosine = Dot(to);
12 if (fabs(cosine) < 1.0 - 1e-3 /* epsilon */) {
13 /*
14 * Spherical Interpolation.
15 */
16 auto sine = sqrt(1.0 - cosine * cosine);
17 auto angle = atan2(sine, cosine);
18 auto sineInverse = 1.0 / sine;
19 auto c0 = sin((1.0 - time) * angle) * sineInverse;
20 auto c1 = sin(time * angle) * sineInverse;
21 return *this * c0 + to * c1;
22 } else {
23 /*
24 * Linear Interpolation.
25 */
26 return (*this * (1.0 - time) + to * time).Normalize();
27 }
28 }
impeller::Quaternion::e
Scalar e[4]
Definition: quaternion.h:22
impeller::Quaternion::Dot
Scalar Dot(const Quaternion &q) const
Definition: quaternion.h:38

References Dot(), e, and Normalize().

## Member Data Documentation

## ◆

union { ... }

## ◆ e

Scalar impeller::Quaternion::e[4]

Definition at line 22 of file quaternion.h.

Referenced by Slerp().

## ◆ w

Scalar impeller::Quaternion::w = 1.0

Definition at line 20 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

## ◆ x

Scalar impeller::Quaternion::x = 0.0

Definition at line 17 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

## ◆ y

Scalar impeller::Quaternion::y = 0.0

Definition at line 18 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

## ◆ z

Scalar impeller::Quaternion::z = 0.0

Definition at line 19 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

The documentation for this struct was generated from the following files:

- impeller/geometry/quaternion.h
- impeller/geometry/quaternion.cc