A quaternion type. Used for rotations in three dimensions.
Construct a quaternion given its four components. The first argument is the scalar component, the rest are the vector components.
The identity quaternion corresponds to no rotation.
identity == quaternion 1 0 0 0Create a quaternion corresponding to a rotation about the x axis by the given angle. Rotation is counter-clockwise.
q = xRotation (degrees 90)
v = vector 0 1 0 -- y axis
rotate q v == vector 0 0 1 -- rotated into z axisCreate a quaternion corresponding to a rotation about the y axis by the given angle.
Create a quaternion corresponding to a rotation about the z axis by the given angle.
Given two vectors, return a quaternion that would rotate the first vector to the second vector. The lengths of the vectors are ignored. If one or both vectors are zero, return the identity quaternion.
Create a quaternion given an axis and angle of rotation. The length of the axis is ignored, but returns Nothing if the axis is the zero vector.
Convert a rotation vector to a quaternion. A rotation vector's direction is the axis of rotation, and its length is the angle of rotation.
Convert a quaternion to a rotation vector.
Returns true if two quaternions represent the same rotation.
Rotation depends on the direction that a quaternion points in, but not its length.
The zero quaternion is only similar to itself.
Multiply two quaternions.
Multiplication with the operands flipped.
This can make multiplication easier to use along with the pipe operators |> and <|
compose p q == mul q pThe conjugate of a quaternion.
Rotate a vector by a quaternion.
The quaternion does not have to be a unit quaternion. The vector length will be preserved.
If given the zero quaternion, no rotation will be performed.
Rotate vector in the opposite direction. reverseRotate q v == rotate (conjugate q) v
Convert to a Json Value.
A Json Decoder for vectors encoded with encode.
Convert to an elm-linear-algebra Mat4
These functions are not as useful if you are just using quaternions to handle 3D rotations.
Returns true when two quaternions are about equal (within 10^-5).
Get scalar component.
Get first vector component.
Get second vector component.
Get third vector component.
Return the unit quaternion that points in the same direction as the given quaternion. Return Nothing if given the zero quaternion.
The square of the length.
The length, or norm, of the quaternion.
Add two quaternions.
If you are trying to combine rotations, you should to use mul or compose instead.
Multiply all of the quaternion's components by a factor.
Quaternion is a combination of a 3-vector and a scalar.