Page not found
- -Sorry, but the page you were trying to get to, does not exist. You -may want to try searching this site using the sidebar - or using our API Reference page -to find what you were looking for.
- - -diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore index ba47db6..fdaf4aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,17 @@ # The directory Mix will write compiled artifacts to. -/_build +/_build/ # If you run "mix test --cover", coverage assets end up here. -/cover +/cover/ # The directory Mix downloads your dependencies sources to. -/deps +/deps/ -# Where 3rd-party dependencies like ExDoc output generated docs. -/doc +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch # If the VM crashes, it generates a dump, let's ignore it too. erl_crash.dump @@ -16,6 +19,13 @@ erl_crash.dump # Also ignore archive artifacts (built via "mix archive.build"). *.ez -.elixir_ls +# Ignore package tarball (built via "mix hex.build"). +vector-*.tar + +# Temporary files for e.g. tests. +/tmp/ -.DS_Store \ No newline at end of file +# Misc. +.DS_Store +.elixir_ls/ +/bench/snapshots/ diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/README.md b/README.md index bf768ad..62f4a73 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,30 @@ # Vector Math Library for Elixir [](https://travis-ci.org/pkinney/vector_ex) -[](https://hex.pm/packages/vector) +[](https://hex.pm/packages/vector) +[](https://hexdocs.pm/vector/) +[](https://hex.pm/packages/vector) +[](https://github.com/pkinney/vector/blob/master/LICENSE) +[](https://github.com/pkinney/vector_ex/commits/master) + Library of common vector functions for use in geometric or graphical calculations. ## Installation +The package can be installed by adding `:vector` to your list of dependencies +in `mix.exs`: + ```elixir defp deps do - [{:vector, "~> 1.0"}] + [ + {:vector, "~> 1.0"} + ] end ``` ## Usage -**[Full Documentation](https://hexdocs.pm/vector/Vector.html)** - 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 @@ -32,12 +40,44 @@ Vector.subtract({2, 0, -1}, {1, 3}) #=> {1, -3, 1} Vector.component({2, 3, -2}, :y) #=> 3 ``` -## Tests +Included in the project are a suite of +[algebraic identities](https://en.wikipedia.org/wiki/Vector_algebra_relations#Addition_and_multiplication_of_vectors) that can be run against a large generated set of vectors. + +## Benchmark ```bash -> mix test +$ mix bench + +Settings: + duration: 1.0 s + +## VectorBench +[03:00:07] 1/8: A . (B x C) +[03:00:09] 2/8: A . B +[03:00:10] 3/8: A x (B x C) +[03:00:12] 4/8: A x B +[03:00:14] 5/8: B (A . C) - C (A . B) +[03:00:16] 6/8: unit vector +[03:00:20] 7/8: zero-vector cross 2D +[03:00:31] 8/8: zero-vector cross 3D + +Finished in 25.05 seconds + +## VectorBench +benchmark name iterations average time +zero-vector cross 2D 100000000 0.10 µs/op +zero-vector cross 3D 10000000 0.13 µs/op +A . B 1000 1091.15 µs/op +A x B 1000 1476.54 µs/op +unit vector 500 7180.52 µs/op +A x (B x C) 10 164521.80 µs/op +A . (B x C) 5 272087.20 µs/op +B (A . C) - C (A . B) 2 619590.00 µs/op ``` -Included in the project are a suite of -[algebraic identities](https://en.wikipedia.org/wiki/Vector_algebra_relations#Addition_and_multiplication_of_vectors) -that can be run against a large generated set of vectors. +## Copyright and License + +Copyright (c) 2017 Powell Kinney + +This library is released under the MIT License. See the [LICENSE.md](./LICENSE.md) file +for further details. diff --git a/doc/.build b/doc/.build deleted file mode 100644 index 0a55033..0000000 --- a/doc/.build +++ /dev/null @@ -1,12 +0,0 @@ -dist/html-399e30b9b028e3059575.css -dist/html-399e30b9b028e3059575.js -dist/html/fonts/icomoon.eot -dist/html/fonts/icomoon.svg -dist/html/fonts/icomoon.ttf -dist/html/fonts/icomoon.woff -dist/sidebar_items-71d22232a3.js -api-reference.html -search.html -404.html -Vector.html -index.html diff --git a/doc/404.html b/doc/404.html deleted file mode 100644 index 26f8b56..0000000 --- a/doc/404.html +++ /dev/null @@ -1,86 +0,0 @@ - - -
- - - - -Sorry, but the page you were trying to get to, does not exist. You -may want to try searching this site using the sidebar - or using our API Reference page -to find what you were looking for.
- - -A library of two- and three-dimensional vector operations. All vectors -are represented as tuples with either two or three elements.
-iex> # Vector Tripple Product Identity
-...> a = {2, 3, 1}
-...> b = {1, 4, -2}
-...> c = {-1, 2, 1}
-...> Vector.equal?(
-...> Vector.cross(Vector.cross(a, b), c),
-...> Vector.subtract(Vector.multiply(b, Vector.dot(a, c)), Vector.multiply(a, Vector.dot(b, c))))
-true
- Adds two vectors
-Returns the basis vector for the given axis
-Returns the scalar component for the axis given
-Returns the cross product of two vectors A⨯B
-Returns the norm (magnitude) of the cross product of two vectors A⨯B
-Divide a vector by scalar value s
Returns the dot product of two vectors A⨯B
-Compares two vectors for euqality, with an optional tolerance
-Multiply a vector by scalar value s
Returns the norm (magnitude) of a vector
-Returns the square of the norm norm (magnitude) of a vector
-Returns a new coordinate by projecting a given length distance from
-coordinate start along vector
Reverses a vector
-Subtract vector B from vector A. Equivalent to Vector.add(A, Vector.revers(B))
Returns the unit vector parallel ot the given vector.
-This will raise an ArithmeticError if a zero-magnitude vector is given.
-Use unit_safe if there is a chance that a zero-magnitude vector
-will be sent
Returns the unit vector parallel ot the given vector, but will handle
-the vectors {0, 0} and {0, 0, 0} by returning the same vector
Adds two vectors
-iex> Vector.add({3, -4}, {2, 1})
-{5,-3}
-iex> Vector.add({-2, 0, 5}, {0, 0, 0})
-{-2, 0, 5}
-iex> Vector.add({2, 1, -2}, Vector.reverse({2, 1, -2}))
-{0, 0, 0}
- Returns the basis vector for the given axis
-iex> Vector.basis(:x)
-{1, 0, 0}
-iex> Vector.basis(:y)
-{0, 1, 0}
-iex> Vector.component(Vector.basis(:y), :y)
-1
- Returns the scalar component for the axis given
-iex> Vector.component({3, -4}, :y)
--4
-iex> Vector.component({-6, 0, 8}, :z)
-8
-iex> Vector.component({1, -2}, :z)
-0
-iex> Vector.component(Vector.basis(:x), :z)
-0
- Returns the cross product of two vectors A⨯B
-iex> Vector.cross({2, 3}, {1, 4})
-{0, 0, 5}
-iex> Vector.cross({2, 2, -1}, {1, 4, 2})
-{8, -5, 6}
-iex> Vector.cross({3, -3, 1}, {4, 9, 2})
-{-15, -2, 39}
- Returns the norm (magnitude) of the cross product of two vectors A⨯B
-iex> Vector.cross_norm({2, 3}, {1, 4})
-5
-iex> Vector.cross_norm({1, 4}, {2, 2})
-6
-iex> Vector.cross_norm({2, 0, -1}, {0, 3, 3})
-9.0
-iex> Float.floor(:math.pow(Vector.cross_norm({2, 2, -1}, {1, 4, 2}), 2))
-125.0
- Divide a vector by scalar value s
iex> Vector.divide({3, -4}, 2.5)
-{1.2, -1.6}
-iex> Vector.divide({-2, 0, 5}, -2)
-{1.0, 0.0, -2.5}
- Returns the dot product of two vectors A⨯B
-iex> Vector.dot({2, 3}, {1, 4})
-14
-iex> Vector.dot({1, 4}, {2, 2})
-10
-iex> Vector.dot({2, 0, -1}, {0, 3, 3})
--3
- Compares two vectors for euqality, with an optional tolerance
-iex> Vector.equal?({3, -4}, {3, -4})
-true
-iex> Vector.equal?({3, -4}, {3.0001, -3.9999})
-false
-iex> Vector.equal?({3, -4}, {3.0001, -3.9999}, 0.001)
-true
-iex> Vector.equal?({3, -4, 1}, {3.0001, -3.9999, 1.0}, 0.001)
-true
- Multiply a vector by scalar value s
iex> Vector.multiply({3, -4}, 2.5)
-{7.5, -10.0}
-iex> Vector.multiply({-2, 0, 5}, -2)
-{4, 0, -10}
- Returns the norm (magnitude) of a vector
-iex> Vector.norm({3, 4})
-5.0
-iex> Vector.norm({-1, 0})
-1
-iex> Vector.norm({0, -2, 0})
-2
- Returns the square of the norm norm (magnitude) of a vector
-iex> Vector.norm_squared({3, 4})
-25
-iex> Vector.norm_squared({1, 0})
-1
-iex> Vector.norm_squared({2, 0, -1})
-5
-iex> Vector.norm_squared({-2, 3, 1})
-14
- Returns a new coordinate by projecting a given length distance from
-coordinate start along vector
iex> Vector.project({3, -4}, {-1, 1}, 4)
-{1.4, -2.2}
-iex> Vector.project({-6, 0, 8}, {1, -2, 0.4}, 2.5)
-{-0.5, -2.0, 2.4}
-iex> Vector.project({-2, 1, 3}, {0, 0, 0}, 2.5) |> Vector.norm()
-2.5
- Reverses a vector
-iex> Vector.reverse({3, -4})
-{-3, 4}
-iex> Vector.reverse({-2, 0, 5})
-{2, 0, -5}
-iex> Vector.cross_norm({-2, 3, 5}, Vector.reverse({-2, 3, 5}))
-0
- Subtract vector B from vector A. Equivalent to Vector.add(A, Vector.revers(B))
iex> Vector.subtract({3, -4}, {2, 1})
-{1,-5}
-iex> Vector.subtract({-2, 0, 5}, {-3, 1, 2})
-{1, -1, 3}
- Returns the unit vector parallel ot the given vector.
-This will raise an ArithmeticError if a zero-magnitude vector is given.
-Use unit_safe if there is a chance that a zero-magnitude vector
-will be sent.
iex> Vector.unit({3, 4})
-{0.6, 0.8}
-iex> Vector.unit({8, 0, 6})
-{0.8, 0.0, 0.6}
-iex> Vector.unit({-2, 0, 0})
-{-1.0, 0.0, 0.0}
-iex> Vector.unit({0, 0, 0})
-** (ArithmeticError) bad argument in arithmetic expression
- Returns the unit vector parallel ot the given vector, but will handle
-the vectors {0, 0} and {0, 0, 0} by returning the same vector
iex> Vector.unit_safe({3, 4})
-{0.6, 0.8}
-iex> Vector.unit_safe({0, 0})
-{0, 0}
-iex> Vector.unit_safe({0, 0, 0})
-{0, 0, 0}
- A library of two- and three-dimensional vector operations. All vectors -are represented as tuples with either two or three elements
-