From 6f691f9f26379447ceac31da1949eba16761c9db Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Dec 2023 18:36:51 +0100 Subject: [PATCH] Rework MLPPVector::cross(). --- mlpp/lin_alg/mlpp_vector.cpp | 22 ++++++++++++++-------- mlpp/lin_alg/mlpp_vector.h | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mlpp/lin_alg/mlpp_vector.cpp b/mlpp/lin_alg/mlpp_vector.cpp index 5026c8c..75c7671 100644 --- a/mlpp/lin_alg/mlpp_vector.cpp +++ b/mlpp/lin_alg/mlpp_vector.cpp @@ -851,18 +851,24 @@ real_t MLPPVector::dot(const Ref &b) const { return c; } -/* -std::vector MLPPVector::cross(std::vector a, std::vector b) { +Ref MLPPVector::cross(const Ref &b) { // Cross products exist in R^7 also. Though, I will limit it to R^3 as Wolfram does this. - std::vector> mat = { onevec(3), a, b }; + //std::vector> mat = { onevec(3), a, b }; - real_t det1 = det({ { a[1], a[2] }, { b[1], b[2] } }, 2); - real_t det2 = -det({ { a[0], a[2] }, { b[0], b[2] } }, 2); - real_t det3 = det({ { a[0], a[1] }, { b[0], b[1] } }, 2); + real_t det1 = element_get(1) * b->element_get(2) - element_get(2) * b->element_get(1); + real_t det2 = -(element_get(0) * b->element_get(2) - element_get(2) * b->element_get(0)); + real_t det3 = element_get(0) * b->element_get(1) - element_get(1) * b->element_get(0); - return { det1, det2, det3 }; + Ref ret; + ret.instance(); + ret->resize(3); + + ret->element_set(0, det1); + ret->element_set(1, det2); + ret->element_set(2, det3); + + return ret; } -*/ void MLPPVector::abs() { real_t *out_ptr = ptrw(); diff --git a/mlpp/lin_alg/mlpp_vector.h b/mlpp/lin_alg/mlpp_vector.h index 3452b01..38da75b 100644 --- a/mlpp/lin_alg/mlpp_vector.h +++ b/mlpp/lin_alg/mlpp_vector.h @@ -195,7 +195,7 @@ public: real_t dot(const Ref &b) const; - //std::vector cross(std::vector a, std::vector b); + Ref cross(const Ref &b); void abs(); Ref absn() const;