diff options
| -rw-r--r-- | modules/codec/c++/math.hpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/codec/c++/math.hpp b/modules/codec/c++/math.hpp index a8bbba1..6e1ec8b 100644 --- a/modules/codec/c++/math.hpp +++ b/modules/codec/c++/math.hpp @@ -81,5 +81,31 @@ data<schema::Vector<T,M>, Encoding> multiply(const data<schema::Matrix<T,M,N>, E return lr; } + +template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> +data<schema::Vector<T,3u>, Encoding> cross( + const data<schema::Vector<T,3u>, Encoding> lh, + const data<schema::Vector<T,3u>, Encoding> rh +){ + data<schema::Vector<T,3u>, Encoding> cross_prod; + + cross_prod.at({{0u}}) = lh.at({{1u}}) * rh.at({{2u}}) - lh.at({{2u}}) * rh.at({{1u}}); + cross_prod.at({{1u}}) = lh.at({{2u}}) * rh.at({{0u}}) - lh.at({{0u}}) * rh.at({{2u}}); + cross_prod.at({{2u}}) = lh.at({{0u}}) * rh.at({{1u}}) - lh.at({{1u}}) * rh.at({{0u}}); + + return cross_prod; +} + +template<typename T, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING> +data<T,Encoding> cross( + const data<schema::Vector<T,2u>, Encoding> lh, + const data<schema::Vector<T,2u>, Encoding> rh +){ + data<T, Encoding> cross_prod; + + cross_prod = lh.at({{0u}}) * rh.at({{1u}}) - lh.at({{1u}}) * rh.at({{0u}}); + + return cross_prod; +} } } |
