Search documentation of bb

# BB.Message.Vec3 (bb v0.8.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

## Types

t()

## Functions

from_list(list)

Create from a list [x, y, z].

new(x, y, z)

Create a new vec3 from x, y, z components.

to_list(arg)

Convert to a list [x, y, z].

unit_x()

Returns a unit vector along the X axis.

unit_y()

Returns a unit vector along the Y axis.

unit_z()

Returns a unit vector along the Z axis.

x(arg)

Get the X component.

y(arg)

Get the Y component.

z(arg)

Get the Z component.

zero()

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}