/*************************************************************************** * Copyright (c) 2023 Ondsel, Inc. * * * * This file is part of OndselSolver. * * * * See LICENSE file for details about copyright. * ***************************************************************************/ #include "EulerAngles.h" namespace MbD { template inline void EulerAngles::initialize() { assert(false); } template<> inline void EulerAngles::calc() { cA = std::make_shared>(3); for (int i = 0; i < 3; i++) { auto axis = rotOrder->at(i); auto angle = this->at(i)->getValue(); if (axis == 1) { cA->atiput(i, FullMatrixDouble::rotatex(angle)); } else if (axis == 2) { cA->atiput(i, FullMatrixDouble::rotatey(angle)); } else if (axis == 3) { cA->atiput(i, FullMatrixDouble::rotatez(angle)); } else { throw std::runtime_error("Euler angle rotation order must be any permutation of 1,2,3 without consecutive repeats."); } } aA = cA->at(0)->timesFullMatrix(cA->at(1)->timesFullMatrix(cA->at(2))); } template<> inline void EulerAngles::calc() { cA = std::make_shared>(3); for (int i = 0; i < 3; i++) { auto axis = rotOrder->at(i); auto angle = this->at(i); if (axis == 1) { cA->atiput(i, FullMatrixDouble::rotatex(angle)); } else if (axis == 2) { cA->atiput(i, FullMatrixDouble::rotatey(angle)); } else if (axis == 3) { cA->atiput(i, FullMatrixDouble::rotatez(angle)); } else { throw std::runtime_error("Euler angle rotation order must be any permutation of 1,2,3 without consecutive repeats."); } } aA = cA->at(0)->timesFullMatrix(cA->at(1)->timesFullMatrix(cA->at(2))); } template inline void EulerAngles::calc() { assert(false); } template inline void EulerAngles::setRotOrder(int i, int j, int k) { rotOrder = std::make_shared>(3); rotOrder->at(0) = i; rotOrder->at(1) = j; rotOrder->at(2) = k; } // type-specific helper functions std::shared_ptr>> differentiateWRT(EulerAngles>& ref, std::shared_ptr var) { auto derivatives = std::make_shared>>(); std::transform(ref.begin(), ref.end(), derivatives->begin(), [var](std::shared_ptr term) { return term->differentiateWRT(var); } ); derivatives->aEulerAngles = &ref; return derivatives; } }