Quaternion class

A mutable rotation quaternion (x, y, z, w), Hamilton convention.

A vector is rotated as q · v · q⁻¹; composing a · b applies b first, then a. Rotations are right-handed about their axis, so in the engine's world (X right, Y down, Z into the screen) a positive turn about Z carries +X towards +Y — clockwise on screen, like Canvas.rotate.

Euler angles

There is exactly one Euler convention in the Just packages:

q = qY(y) · qX(x) · qZ(z)        R = Ry · Rx · Rz

i.e. Z is applied first, then X, then Y, all about the fixed world axes (the order Unity uses). A 2-D rotation is (0, 0, angle).

Like Vector3, every operation works in place so hot paths never allocate; methods that take an out parameter are safe to alias.

Constructors

Quaternion(double x, double y, double z, double w)
Create from raw components (not normalised).
Quaternion.axisAngle(Vector3 axis, double angle)
A rotation of angle radians about axis (need not be normalised).
Quaternion.copy(Quaternion other)
Copy constructor.
Quaternion.euler(double ex, double ey, double ez)
The rotation with Euler angles ex, ey, ez (radians).
Quaternion.identity()
The identity rotation.

Properties

hashCode → int
The hash code for this object.
no setteroverride
length → double
Norm.
no setter
lengthSquared → double
Squared norm.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
w ↔ double
Scalar part.
getter/setter pair
x ↔ double
Vector part, x.
getter/setter pair
y ↔ double
Vector part, y.
getter/setter pair
z ↔ double
Vector part, z.
getter/setter pair

Methods

conjugate() → void
Negate the vector part. For a unit quaternion this is the inverse.
dot(Quaternion other) → double
Four-dimensional dot product.
eulerInto(Vector3 out, {Vector3? hint}) → void
Write this rotation's Euler angles (radians, see the class docs) into out.
invert() → void
Invert in place (works for non-unit quaternions too).
isIdentity([double epsilon = 1e-12]) → bool
Whether this is the identity rotation, within epsilon.
multiply(Quaternion other) → void
this = this · other — apply other first, then the old this.
normalize() → double
Normalise in place. Returns the original length; a zero quaternion becomes the identity.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
premultiply(Quaternion other) → void
this = other · this — apply the old this first, then other.
rotate(Vector3 v) → void
Rotate v in place.
rotateInto(Vector3 input, Vector3 out) → void
Write input rotated by this into out. Safe when out == input.
sameRotation(Quaternion other, [double epsilon = 1e-9]) → bool
Whether this and other are the same rotation within epsilon (q and -q count as the same).
setAxisAngle(double ax, double ay, double az, double angle) → void
Set to a rotation of angle radians about the axis (ax, ay, az). A zero axis gives the identity.
setEuler(double ex, double ey, double ez) → void
Set from Euler angles in radians: q = qY(ey) · qX(ex) · qZ(ez).
setFrom(Quaternion other) → void
Set to other.
setFromRotationElements(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) → void
Set from a rotation matrix given by its elements (row, column).
setIdentity() → void
Set to the identity rotation.
setProduct(Quaternion a, Quaternion b) → void
Set to a · b (apply b, then a). Safe when either is this.
setRotationZ(double angle) → void
Set to a rotation of angle radians about +Z — the 2-D rotation.
setSlerp(Quaternion a, Quaternion b, double t) → void
Set to the spherical interpolation from a (t = 0) to b (t = 1), along the shorter arc. Safe when this is a or b.
setValues(double nx, double ny, double nz, double nw) → void
Set raw components.
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
Exact component equality: q and -q are the same rotation but not equal (use sameRotation). The value is mutable, so a quaternion must not change while it is a key in a set or map.
override