From 6f3fdf4d4945bb24e807050147a3766c49611dff Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 21 Oct 2020 18:36:57 +0300 Subject: [PATCH] pimathvector.h mul --- libs/main/math/pimathvector.h | 50 ++++++++++++++++++++++++++++++++++- main.cpp | 9 +++---- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 010b74e3..8983fd37 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -149,6 +149,14 @@ public: PIMV_FOR tv += c[i] * v[i]; return tv; } + _CVector mul(const _CVector & v) const { + _CVector tv(*this); + PIMV_FOR tv[i] *= v[i]; + return tv; + } + _CVector mul(const Type & v) const { + return (*this) * v; + } PIMathMatrixT<1, Size, Type> transposed() const { PIMathMatrixT<1, Size, Type> ret; @@ -172,6 +180,22 @@ public: return tv; } + static _CVector cross(const _CVector & v1, const _CVector & v2) { + return v1.cross(v2); + } + static _CVector dot(const _CVector & v1, const _CVector & v2) { + return v1.dot(v2); + } + static _CVector mul(const _CVector & v1, const _CVector & v2) { + return v1.mul(v2); + } + static _CVector mul(const Type & v1, const _CVector & v2) { + return v2 * v1; + } + static _CVector mul(const _CVector & v1, const Type & v2) { + return v1 * v2; + } + private: Type c[Size]; @@ -372,6 +396,15 @@ public: PIMV_FOR tv += c[i] * v[i]; return tv; } + _CVector mul(const _CVector & v) const { + assert(c.size() == v.size()); + _CVector tv(*this); + PIMV_FOR tv[i] *= v[i]; + return tv; + } + _CVector mul(const Type & v) const { + return (*this) * v; + } Type distToLine(const _CVector & lp0, const _CVector & lp1) { assert(c.size() == lp0.size()); @@ -388,9 +421,24 @@ public: inline Type * data() {return c.data();} inline const Type * data() const {return c.data();} + + static _CVector cross(const _CVector & v1, const _CVector & v2) { + return v1.cross(v2); + } + static _CVector dot(const _CVector & v1, const _CVector & v2) { + return v1.dot(v2); + } + static _CVector mul(const _CVector & v1, const _CVector & v2) { + return v1.mul(v2); + } + static _CVector mul(const Type & v1, const _CVector & v2) { + return v2 * v1; + } + static _CVector mul(const _CVector & v1, const Type & v2) { + return v1 * v2; + } private: PIVector c; - }; template diff --git a/main.cpp b/main.cpp index e4194112..072c42ab 100644 --- a/main.cpp +++ b/main.cpp @@ -40,11 +40,8 @@ inline PIByteArray & operator >>(PIByteArray & ba, MM & v) {piCout << ">>" int main() { - PIMathMatrixd m = PIMathMatrixd::identity(5,5); -// m.fill(9); - //PIMathMatrixd m2 = PIMathMatrixd::identity(3,4); - piCout << m; - m.resize(3,3); - piCout << m; + PIMathVectorT3d v3 = createVectorT3d(1,2,3); + PIMathVectord v(v3); + piCout << v; return 0; }