BB.Message.Quaternion (bb v0.4.0)
View SourceHelper functions for quaternion tagged tuples.
Quaternions are represented as {:quaternion, x, y, z, w} where components
are floats in XYZW order. Used for representing 3D orientations.
The quaternion should be normalised (magnitude = 1) for rotation purposes, but this module does not enforce normalisation.
Examples
iex> alias BB.Message.Quaternion
iex> q = Quaternion.identity()
{:quaternion, 0.0, 0.0, 0.0, 1.0}
iex> Quaternion.w(q)
1.0
Summary
Functions
Create from a list [x, y, z, w].
Returns the identity quaternion (no rotation).
Create a new quaternion from x, y, z, w components.
Convert to a list [x, y, z, w].
Get the W (scalar) component.
Get the X component.
Get the Y component.
Get the Z component.
Types
Functions
Create from a list [x, y, z, w].
Examples
iex> BB.Message.Quaternion.from_list([0.0, 0.0, 0.0, 1.0])
{:quaternion, 0.0, 0.0, 0.0, 1.0}
@spec identity() :: t()
Returns the identity quaternion (no rotation).
Examples
iex> BB.Message.Quaternion.identity()
{:quaternion, 0.0, 0.0, 0.0, 1.0}
Create a new quaternion from x, y, z, w components.
Accepts any numeric type and converts to float.
Examples
iex> BB.Message.Quaternion.new(0, 0, 0, 1)
{:quaternion, 0.0, 0.0, 0.0, 1.0}
iex> BB.Message.Quaternion.new(0.0, 0.707, 0.0, 0.707)
{:quaternion, 0.0, 0.707, 0.0, 0.707}
Convert to a list [x, y, z, w].
Examples
iex> BB.Message.Quaternion.to_list({:quaternion, 0.0, 0.0, 0.0, 1.0})
[0.0, 0.0, 0.0, 1.0]
Get the W (scalar) component.
Examples
iex> BB.Message.Quaternion.w({:quaternion, 0.1, 0.2, 0.3, 0.9})
0.9
Get the X component.
Examples
iex> BB.Message.Quaternion.x({:quaternion, 0.1, 0.2, 0.3, 0.9})
0.1
Get the Y component.
Examples
iex> BB.Message.Quaternion.y({:quaternion, 0.1, 0.2, 0.3, 0.9})
0.2
Get the Z component.
Examples
iex> BB.Message.Quaternion.z({:quaternion, 0.1, 0.2, 0.3, 0.9})
0.3