nphollon/geo3d/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

Quaternion

A quaternion type. Used for rotations in three dimensions.

Building

type alias Quaternion =
{ vector : Vector
, scalar : Float
}

Quaternion is a combination of a 3-vector and a scalar.

quaternion : Float -> Float -> Float -> Float -> Quaternion

Construct a quaternion given its four components. The first argument is the scalar component, the rest are the vector components.

identity : Quaternion

The identity quaternion corresponds to no rotation.

identity == quaternion 1 0 0 0
rotateX : Float -> Quaternion

Create a quaternion corresponding to a rotation about the x axis by the given angle. Rotation is counter-clockwise.

q = rotateX (degrees 90)
v = vector 0 1 0 -- y axis


rotateVector q v == vector 0 0 1 -- rotated into z axis
rotateY : Float -> Quaternion

Create a quaternion corresponding to a rotation about the y axis by the given angle.

rotateZ : Float -> Quaternion

Create a quaternion corresponding to a rotation about the z axis by the given angle.

rotationFor : Vector -> Vector -> Quaternion

Given two vectors, return the 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.

fromAxisAngle : Vector -> Float -> Maybe 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.

fromVector : Vector -> Quaternion

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.

toVector : Quaternion -> Vector

Convert a quaternion to a rotation vector.

Transforming

compose : Quaternion -> Quaternion -> Quaternion

Multiply two quaternions.

conjugate : Quaternion -> Quaternion

The conjugate of a quaternion.

rotateVector : Quaternion -> Vector -> Vector

Rotate a vector by a quaternion.

Interop

encode : Quaternion -> Value

Convert to a Json Value.

decode : Decoder Quaternion

A Json Decoder for vectors encoded with encode.

toMat4 : Quaternion -> Mat4