BB.Message.Vec3 (bb v0.4.0)

View Source

Helper 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

t()

@type t() :: {:vec3, float(), float(), float()}

Functions

from_list(list)

@spec from_list([number()]) :: t()

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}

new(x, y, z)

@spec new(number(), number(), number()) :: t()

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}

to_list(arg)

@spec to_list(t()) :: [float()]

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]

unit_x()

@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}

unit_y()

@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}

unit_z()

@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}

x(arg)

@spec x(t()) :: float()

Get the X component.

Examples

iex> BB.Message.Vec3.x({:vec3, 1.0, 2.0, 3.0})
1.0

y(arg)

@spec y(t()) :: float()

Get the Y component.

Examples

iex> BB.Message.Vec3.y({:vec3, 1.0, 2.0, 3.0})
2.0

z(arg)

@spec z(t()) :: float()

Get the Z component.

Examples

iex> BB.Message.Vec3.z({:vec3, 1.0, 2.0, 3.0})
3.0

zero()

@spec zero() :: t()

Returns the zero vector.

Examples

iex> BB.Message.Vec3.zero()
{:vec3, 0.0, 0.0, 0.0}