/*************************************************************************** * Copyright (c) 2023 Ondsel, Inc. * * * * This file is part of OndselSolver. * * * * See LICENSE file for details about copyright. * ***************************************************************************/ #pragma once #include "corecrt_math_defines.h" #include #include "FullRow.h" #include "RowTypeMatrix.h" #include "FullColumn.h" namespace MbD { template class FullMatrix; using FMatDsptr = std::shared_ptr>; template using FMatsptr = std::shared_ptr>; template class FullColumn; using FColDsptr = std::shared_ptr>; template class FullRow; template class RowTypeMatrix; template class EulerParameters; template class DiagonalMatrix; using FMatFColDsptr = std::shared_ptr>; using FMatFMatDsptr = std::shared_ptr>; using FColFMatDsptr = std::shared_ptr>; template class FullMatrix : public RowTypeMatrix> { public: FullMatrix() {} FullMatrix(int m) : RowTypeMatrix>(m) { } FullMatrix(int m, int n) { for (int i = 0; i < m; i++) { auto row = std::make_shared>(n); this->push_back(row); } } FullMatrix(std::initializer_list> listOfRows) { for (auto& row : listOfRows) { this->push_back(row); } } FullMatrix(std::initializer_list> list2D) { for (auto& rowList : list2D) { auto row = std::make_shared>(rowList); this->push_back(row); } } static FMatsptr rotatex(T angle); static FMatsptr rotatey(T angle); static FMatsptr rotatez(T angle); static FMatsptr rotatexrotDot(T angle, T angledot); static FMatsptr rotateyrotDot(T angle, T angledot); static FMatsptr rotatezrotDot(T angle, T angledot); static FMatsptr rotatexrotDotrotDDot(T angle, T angleDot, T angleDDot); static FMatsptr rotateyrotDotrotDDot(T angle, T angleDot, T angleDDot); static FMatsptr rotatezrotDotrotDDot(T angle, T angleDot, T angleDDot); static FMatsptr identitysptr(int n); static FMatsptr tildeMatrix(FColDsptr col); void identity(); FColsptr column(int j); FColsptr timesFullColumn(FColsptr fullCol); FColsptr timesFullColumn(FullColumn* fullCol); FMatsptr timesFullMatrix(FMatsptr fullMat); FMatsptr timesTransposeFullMatrix(FMatsptr fullMat); FMatsptr times(T a); FMatsptr transposeTimesFullMatrix(FMatsptr fullMat); FMatsptr plusFullMatrix(FMatsptr fullMat); FMatsptr minusFullMatrix(FMatsptr fullMat); FMatsptr transpose(); FMatsptr negated(); void symLowerWithUpper(); void atiput(int i, FRowsptr fullRow) override; void atijput(int i, int j, T value); void atijputFullColumn(int i, int j, FColsptr fullCol); void atijplusFullRow(int i, int j, FRowsptr fullRow); void atijplusNumber(int i, int j, T value); void atijminusNumber(int i, int j, T value); double sumOfSquares() override; void zeroSelf() override; FMatsptr copy(); FullMatrix operator+(const FullMatrix fullMat); FColsptr transposeTimesFullColumn(const FColsptr fullCol); void magnifySelf(T factor); std::shared_ptr> asEulerParameters(); T trace(); double maxMagnitude() override; FColsptr bryantAngles(); bool isDiagonal(); bool isDiagonalToWithin(double ratio); std::shared_ptr> asDiagonalMatrix(); void conditionSelfWithTol(double tol); std::ostream& printOn(std::ostream& s) const override; }; template inline FMatsptr FullMatrix::rotatex(T the) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, 1.0); row0->atiput(1, 0.0); row0->atiput(2, 0.0); auto row1 = rotMat->at(1); row1->atiput(0, 0.0); row1->atiput(1, cthe); row1->atiput(2, -sthe); auto row2 = rotMat->at(2); row2->atiput(0, 0.0); row2->atiput(1, sthe); row2->atiput(2, cthe); return rotMat; } template inline FMatsptr FullMatrix::rotatey(T the) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, cthe); row0->atiput(1, 0.0); row0->atiput(2, sthe); auto row1 = rotMat->at(1); row1->atiput(0, 0.0); row1->atiput(1, 1.0); row1->atiput(2, 0.0); auto row2 = rotMat->at(2); row2->atiput(0, -sthe); row2->atiput(1, 0.0); row2->atiput(2, cthe); return rotMat; } template inline FMatsptr FullMatrix::rotatez(T the) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, cthe); row0->atiput(1, -sthe); row0->atiput(2, 0.0); auto row1 = rotMat->at(1); row1->atiput(0, sthe); row1->atiput(1, cthe); row1->atiput(2, 0.0); auto row2 = rotMat->at(2); row2->atiput(0, 0.0); row2->atiput(1, 0.0); row2->atiput(2, 1.0); return rotMat; } template inline FMatsptr FullMatrix::rotatexrotDot(T the, T thedot) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto sthedot = cthe * thedot; auto cthedot = -sthe * thedot; auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, 0.0); row0->atiput(1, 0.0); row0->atiput(2, 0.0); auto row1 = rotMat->at(1); row1->atiput(0, 0.0); row1->atiput(1, cthedot); row1->atiput(2, -sthedot); auto row2 = rotMat->at(2); row2->atiput(0, 0.0); row2->atiput(1, sthedot); row2->atiput(2, cthedot); return rotMat; } template inline FMatsptr FullMatrix::rotateyrotDot(T the, T thedot) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto sthedot = cthe * thedot; auto cthedot = -sthe * thedot; auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, cthedot); row0->atiput(1, 0.0); row0->atiput(2, sthedot); auto row1 = rotMat->at(1); row1->atiput(0, 0.0); row1->atiput(1, 0.0); row1->atiput(2, 0.0); auto row2 = rotMat->at(2); row2->atiput(0, -sthedot); row2->atiput(1, 0.0); row2->atiput(2, cthedot); return rotMat; } template inline FMatsptr FullMatrix::rotatezrotDot(T the, T thedot) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto sthedot = cthe * thedot; auto cthedot = -sthe * thedot; auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, cthedot); row0->atiput(1, -sthedot); row0->atiput(2, 0.0); auto row1 = rotMat->at(1); row1->atiput(0, sthedot); row1->atiput(1, cthedot); row1->atiput(2, 0.0); auto row2 = rotMat->at(2); row2->atiput(0, 0.0); row2->atiput(1, 0.0); row2->atiput(2, 0.0); return rotMat; } template inline FMatsptr FullMatrix::rotatexrotDotrotDDot(T the, T thedot, T theddot) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto sthedot = cthe * thedot; auto cthedot = -sthe * thedot; auto stheddot = cthedot * thedot + (cthe * theddot); auto ctheddot = -(sthedot * thedot) - (sthe * theddot); auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, 0.0); row0->atiput(1, 0.0); row0->atiput(2, 0.0); auto row1 = rotMat->at(1); row1->atiput(0, 0.0); row1->atiput(1, ctheddot); row1->atiput(2, -stheddot); auto row2 = rotMat->at(2); row2->atiput(0, 0.0); row2->atiput(1, stheddot); row2->atiput(2, ctheddot); return rotMat; } template inline FMatsptr FullMatrix::rotateyrotDotrotDDot(T the, T thedot, T theddot) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto sthedot = cthe * thedot; auto cthedot = -sthe * thedot; auto stheddot = cthedot * thedot + (cthe * theddot); auto ctheddot = -(sthedot * thedot) - (sthe * theddot); auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, ctheddot); row0->atiput(1, 0.0); row0->atiput(2, stheddot); auto row1 = rotMat->at(1); row1->atiput(0, 0.0); row1->atiput(1, 0.0); row1->atiput(2, 0.0); auto row2 = rotMat->at(2); row2->atiput(0, -stheddot); row2->atiput(1, 0.0); row2->atiput(2, ctheddot); return rotMat; } template inline FMatsptr FullMatrix::rotatezrotDotrotDDot(T the, T thedot, T theddot) { auto sthe = std::sin(the); auto cthe = std::cos(the); auto sthedot = cthe * thedot; auto cthedot = -sthe * thedot; auto stheddot = cthedot * thedot + (cthe * theddot); auto ctheddot = -(sthedot * thedot) - (sthe * theddot); auto rotMat = std::make_shared>(3, 3); auto row0 = rotMat->at(0); row0->atiput(0, ctheddot); row0->atiput(1, -stheddot); row0->atiput(2, 0.0); auto row1 = rotMat->at(1); row1->atiput(0, stheddot); row1->atiput(1, ctheddot); row1->atiput(2, 0.0); auto row2 = rotMat->at(2); row2->atiput(0, 0.0); row2->atiput(1, 0.0); row2->atiput(2, 0.0); return rotMat; } template inline FMatsptr FullMatrix::identitysptr(int n) { auto mat = std::make_shared>(n, n); mat->identity(); return mat; } }