Vector3D (stella v0.7.1)

Documentation for Vector 3D.

Link to this section Summary

Functions

Increment one vector by another one

Calculate distance between vectors

Divide vector by another one

Check if given vectors are equal

Returns vector length

Multiply vector by another one

Create a new two dimensional vector from given values

Scale vector by given scalar

Decrement one vector by another one

Convert vector from struct to list

Convert vector from list to struct

Link to this section Functions

Link to this function

add(curr_vector, given_vector)

@spec add(%{x: number(), y: number(), z: number()}, %{
  x: number(),
  y: number(),
  z: number()
}) :: %{
  x: number(),
  y: number(),
  z: number()
}

Increment one vector by another one

examples

Examples

iex> Vector3D.add(%{x: 2, y: 2, z: 2}, %{x: 2, y: 2, z: 2})
%{x: 4, y: 4, z: 4}

iex> Vector3D.new(-3, 3, 4) |> Vector3D.add(%{x: 3, y: 6, z: 3})
%{x: 0, y: 9, z: 7}
Link to this function

distance(curr_vector, given_vector)

@spec distance(%{x: number(), y: number(), z: number()}, %{
  x: number(),
  y: number(),
  z: number()
}) ::
  float()

Calculate distance between vectors

examples

Examples

iex> Vector3D.distance(%{x: 2.0, y: 2.0, z: 2.0}, %{x: 2, y: 2.0, z: 2.0})
0.0

iex> Vector3D.distance(%{x: -2, y: 4, z: 5}, %{x: 2, y: 2.0, z: 1})
6.0
Link to this function

divide(curr_vector, given_vector)

@spec divide(%{x: number(), y: number(), z: number()}, %{
  x: number(),
  y: number(),
  z: number()
}) :: %{
  x: number(),
  y: number(),
  z: number()
}

Divide vector by another one

examples

Examples

iex> Vector3D.divide(%{x: 2, y: 2, z: 2}, %{x: 2, y: 2, z: 2})
%{x: 1.0, y: 1.0, z: 1.0}

iex> Vector3D.new(-3, 3, 3) |> Vector3D.divide(%{x: 2, y: 3, z: 2})
%{x: -1.5, y: 1.0, z: 1.5}
Link to this function

equals(curr_vector, given_vector)

@spec equals(%{x: number(), y: number(), z: number()}, %{
  x: number(),
  y: number(),
  z: number()
}) ::
  boolean()

Check if given vectors are equal

examples

Examples

iex> Vector3D.equals(%{x: 2, y: 2, z: 2}, %{x: 2, y: 2, z: 2})
true

iex> Vector3D.equals(%{x: 2, y: 2, z: 2}, %{x: 2.0, y: 2.0, z: 2.0})
true

iex> Vector3D.equals(%{x: 2.0, y: 2.0, z: 2.0}, %{x: 2, y: 2, z: 2})
true

iex> Vector3D.equals(%{x: 2.0, y: 2.0, z: 2.0}, %{x: 2, y: 2.0, z: 2.0})
true

iex> Vector3D.new(-3, 3, 3) |> Vector3D.equals(%{x: 2, y: 3, z: 2})
false
@spec length(%{x: number(), y: number(), z: number()}) :: float()

Returns vector length

two-dimensional-vector-length-chart

Two dimensional vector length chart

examples

Examples

iex> Vector3D.length(%{x: 2, y: 2, z: 2})
3.4641016151377544

iex> Vector3D.new(-3, 3, 1) |> Vector3D.length()
4.358898943540674
Link to this function

multiply(curr_vector, given_vector)

@spec multiply(%{x: number(), y: number(), z: number()}, %{
  x: number(),
  y: number(),
  z: number()
}) :: %{
  x: number(),
  y: number(),
  z: number()
}

Multiply vector by another one

examples

Examples

iex> Vector3D.multiply(%{x: 2, y: 2, z: 2}, %{x: 2, y: 2, z: 2})
%{x: 4, y: 4, z: 4}

iex> Vector3D.new(-3, 3, 2) |> Vector3D.multiply(%{x: 2, y: 3, z: 2})
%{x: -6, y: 9, z: 4}
Link to this function

new(x \\ 0, y \\ 0, z \\ 0)

@spec new(number(), number(), number()) :: %{x: number(), y: number(), z: number()}

Create a new two dimensional vector from given values

examples

Examples

iex> Vector3D.new(10, 1)
%{x: 10, y: 1, z: 0}

iex> Vector3D.new()
%{x: 0, y: 0, z: 0}
Link to this function

scale(vector, scalar)

@spec scale(%{x: number(), y: number(), z: number()}, float()) :: %{
  x: number(),
  y: number(),
  z: number()
}

Scale vector by given scalar

examples

Examples

iex> Vector3D.scale(%{x: 2, y: 2, z: 2}, 2)
%{x: 4, y: 4, z: 4}

iex> Vector3D.new(-3, 3, 1) |> Vector3D.scale(3)
%{x: -9, y: 9, z: 3}

iex> Vector3D.new(-3, 3, 1) |> Vector3D.scale(3.08)
%{x: -9.24, y: 9.24, z: 3.08}
Link to this function

sub(curr_vector, given_vector)

@spec sub(%{x: number(), y: number(), z: number()}, %{
  x: number(),
  y: number(),
  z: number()
}) :: %{
  x: number(),
  y: number(),
  z: number()
}

Decrement one vector by another one

examples

Examples

iex> Vector3D.sub(%{x: 2, y: 2, z: 2}, %{x: 2, y: 2, z: 2})
%{x: 0, y: 0, z: 0}

iex> Vector3D.new(-3, 3, 5) |> Vector3D.sub(%{x: 3, y: 6, z: 5})
%{x: -6, y: -3, z: 0}
Link to this function

to_list(vector)

@spec to_list(%{x: number(), y: number(), z: number()}) :: [...]

Convert vector from struct to list

examples

Examples

iex> Vector3D.to_list(%{x: 1, y: 2, z: 3})
[1, 2, 3]
Link to this function

to_struct(vector)

@spec to_struct([...]) :: %{x: number(), y: number(), z: number()}

Convert vector from list to struct

examples

Examples

iex> Vector3D.to_struct([1, 2, 3])
%{x: 1, y: 2, z: 3}