BB.Message.Vec3 (bb v0.4.0)
View SourceHelper functions for 3D vector tagged tuples.
Vectors are represented as {:vec3, x, y, z} where x, y, z are floats.
Used for positions (metres), velocities (m/s), forces (N), and other
3D quantities. The meaning depends on context.
All values are in base SI units - no unit conversion is performed.
Examples
iex> alias BB.Message.Vec3
iex> pos = Vec3.new(1.0, 2.0, 3.0)
{:vec3, 1.0, 2.0, 3.0}
iex> Vec3.x(pos)
1.0
Summary
Functions
Create from a list [x, y, z].
Create a new vec3 from x, y, z components.
Convert to a list [x, y, z].
Returns a unit vector along the X axis.
Returns a unit vector along the Y axis.
Returns a unit vector along the Z axis.
Get the X component.
Get the Y component.
Get the Z component.
Returns the zero vector.
Types
Functions
Create from a list [x, y, z].
Examples
iex> BB.Message.Vec3.from_list([1.0, 2.0, 3.0])
{:vec3, 1.0, 2.0, 3.0}
Create a new vec3 from x, y, z components.
Accepts any numeric type and converts to float.
Examples
iex> BB.Message.Vec3.new(1, 2, 3)
{:vec3, 1.0, 2.0, 3.0}
iex> BB.Message.Vec3.new(1.5, 2.5, 3.5)
{:vec3, 1.5, 2.5, 3.5}
Convert to a list [x, y, z].
Examples
iex> BB.Message.Vec3.to_list({:vec3, 1.0, 2.0, 3.0})
[1.0, 2.0, 3.0]
@spec unit_x() :: t()
Returns a unit vector along the X axis.
Examples
iex> BB.Message.Vec3.unit_x()
{:vec3, 1.0, 0.0, 0.0}
@spec unit_y() :: t()
Returns a unit vector along the Y axis.
Examples
iex> BB.Message.Vec3.unit_y()
{:vec3, 0.0, 1.0, 0.0}
@spec unit_z() :: t()
Returns a unit vector along the Z axis.
Examples
iex> BB.Message.Vec3.unit_z()
{:vec3, 0.0, 0.0, 1.0}
Get the X component.
Examples
iex> BB.Message.Vec3.x({:vec3, 1.0, 2.0, 3.0})
1.0
Get the Y component.
Examples
iex> BB.Message.Vec3.y({:vec3, 1.0, 2.0, 3.0})
2.0
Get the Z component.
Examples
iex> BB.Message.Vec3.z({:vec3, 1.0, 2.0, 3.0})
3.0
@spec zero() :: t()
Returns the zero vector.
Examples
iex> BB.Message.Vec3.zero()
{:vec3, 0.0, 0.0, 0.0}