Library of common vector functions for use in geometric or graphical calculations.
defp deps do
[{:vector, "~> 1.1"}]
end
The Vector
module contains several functions that take one or more vectors.
Each vector can be a 2- or 3-element tuple. It is possible to mix two- and
three-dimensional vectors, in which case the z
of the two-dimensional vector
will be assumed 0.
Vector.dot({2, 3}, {1, 4}) #=> 14
Vector.cross({2, 0, -1}, {0, 3, 3}) #=> {3, -6, 6}
Vector.norm({3, -6, 6}) #=> 9
Vector.unit({2, -1}) #=> {0.894, -0.447}
Vector.add({2, 0, -1}, {0, 3, 3}) #=> {2, 3, 1}
Vector.subtract({2, 0, -1}, {1, 3}) #=> {1, -3, 1}
Vector.component({2, 3, -2}, :y) #=> 3
> mix test
Included in the project are a suite of algebraic identities that can be run against a large generated set of vectors.