diff options
author | Nao Pross <naopross@thearcway.org> | 2019-02-22 23:10:07 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-02-22 23:15:47 +0100 |
commit | 50ab88d5d37e2af635997fce7b103f366594c511 (patch) | |
tree | 123585c0deabc01c96e0aa180353016844f19396 /test/example.cpp | |
parent | Undo directory structure change (diff) | |
parent | Fix typos and other minor errors (diff) | |
download | libmm-50ab88d5d37e2af635997fce7b103f366594c511.tar.gz libmm-50ab88d5d37e2af635997fce7b103f366594c511.zip |
Merge branch 'master' into matrices
Diffstat (limited to 'test/example.cpp')
-rw-r--r-- | test/example.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/example.cpp b/test/example.cpp new file mode 100644 index 0000000..3a00f58 --- /dev/null +++ b/test/example.cpp @@ -0,0 +1,62 @@ +#include "mmvec.hpp" + +#include <iostream> +#include <complex> + +int main(int argc, char *argv[]) { + // N dimensional vectors + std::cout << "N dimensional (int) vectors" << std::endl; + mm::vec<int, 5> u {3, 2, 1, 0, 1}; + mm::vec<int, 5> v {1, 2, 3, 4, 5}; + + std::cout << "u = " << u << std::endl; + std::cout << "v = " << v << std::endl; + std::cout << std::endl; + + // basic operations + std::cout << "u + v = " << u + v << std::endl; + std::cout << "u - v = " << u - v << std::endl; + std::cout << "2 * v = " << 2 * v << std::endl; + std::cout << "v * 2 = " << v * 2 << std::endl; + std::cout << "u * v = " << u * v << std::endl; + std::cout << std::endl; + + u += v; + + // three dimensional vectors + std::cout << "three dimensional (double) vectors" << std::endl; + + mm::vec3<double> a {1, 2, 3}; + mm::vec3<double> b {3, 2, 1}; + + std::cout << "a = " << a << std::endl; + std::cout << "b = " << b << std::endl; + std::cout << std::endl; + + std::cout << "a x b = " << mm::vec3<double>::cross(a, b) << std::endl; + std::cout << "zenith(a) = " << a.zenith() << std::endl; + std::cout << "azimuth(a) = " << a.azimuth() << std::endl; + std::cout << "spherical(a) = " << a.spherical() << std::endl; + std::cout << std::endl; + + a -= b; + + // two dimensional vector + std::cout << "two dimensional (complex) vectors" << std::endl; + + mm::vec2<std::complex<float>> j {{1, 2}, {3, -1}}; + mm::vec2<std::complex<float>> k { 5, {-2, 1}}; + + std::cout << "j = " << j << std::endl; + std::cout << "k = " << k << std::endl; + std::cout << std::endl; + + std::cout << "j x k = " << mm::vec2<std::complex<float>>::cross(j, k) << std::endl; + std::cout << "angle(j) = " << j.angle() << std::endl; + std::cout << "polar(j) = " << j.polar() << std::endl; + std::cout << std::endl; + + j *= 10; + + return 0; +} |