Program Listing for File UnitQuaternion.h#
↰ Return to documentation for file (include/Karana/Math/UnitQuaternion.h)
/*
*Copyright(c)2024-2026KaranaDynamicsPtyLtd.Allrightsreserved.
*
*NOTICETOUSER:
*
*Thissourcecodeand/ordocumentation(the"LicensedMaterials")is
*theconfidentialandproprietaryinformationofKaranaDynamicsInc.
*UseoftheseLicensedMaterialsisgovernedbythetermsandconditions
*ofaseparatesoftwarelicenseagreementbetweenKaranaDynamicsandthe
*Licensee("LicenseAgreement").Unlessexpresslypermittedunderthat
*agreement,anyreproduction,modification,distribution,ordisclosure
*oftheLicensedMaterials,inwholeorinpart,toanythirdparty
*withoutthepriorwrittenconsentofKaranaDynamicsisstrictlyprohibited.
*
*THELICENSEDMATERIALSAREPROVIDED"ASIS"WITHOUTWARRANTYOFANYKIND.
*KARANADYNAMICSDISCLAIMSALLWARRANTIES,EXPRESSORIMPLIED,INCLUDING
*BUTNOTLIMITEDTOWARRANTIESOFMERCHANTABILITY,NON-INFRINGEMENT,AND
*FITNESSFORAPARTICULARPURPOSE.
*
*INNOEVENTSHALLKARANADYNAMICSBELIABLEFORANYDAMAGESWHATSOEVER,
*INCLUDINGBUTNOTLIMITEDTOLOSSOFPROFITS,DATA,ORUSE,EVENIF
*ADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGES,WHETHERINCONTRACT,TORT,
*OROTHERWISEARISINGOUTOFORINCONNECTIONWITHTHELICENSEDMATERIALS.
*
*U.S.GovernmentEndUsers:TheLicensedMaterialsarea"commercialitem"
*asdefinedat48C.F.R.2.101,andareprovidedtotheU.S.Government
*onlyasacommercialenditemunderthetermsofthislicense.
*
*AnyuseoftheLicensedMaterialsinindividualorcommercialsoftwaremust
*include,intheuserdocumentationandinternalsourcecodecomments,
*thisNotice,Disclaimer,andU.S.GovernmentUseProvision.
*/
#pragmaonce
#include"Karana/Math/Defs.h"
#include"Karana/Math/RotationMatrix.h"
#include"Karana/Math/RotationVector.h"
#include"Karana/Math/SpatialVector.h"
#include<unsupported/Eigen/EulerAngles>
namespaceKarana::Math{
usingnamespaceEigen;
classUnitQuaternion{
//Constructors
public:
UnitQuaternion(doublex,
doubley,
doublez,
doublew,
boolrenormalize=false,
boolskip_values_check=false);
UnitQuaternion(constQuaterniond&q,
boolrenormalize=false,
boolskip_values_check=false);
UnitQuaternion(constRotationVector&rv);
UnitQuaternion(constVec4&v,boolrenormalize=false,boolskip_values_check=false);
UnitQuaternion(constEigen::AngleAxis<double>&aa);
UnitQuaternion(constVec3&v1,constVec3&v2);
UnitQuaternion(constRotationMatrix&rot);
template<typenameeuler_system>
UnitQuaternion(constEulerAngles<double,euler_system>&ea)
:UnitQuaternion(
Quaterniond(ea),false/*renormalize*/,false/*donotskip_values_check*/){}
std::string_viewtypeString()const;
std::stringdumpString(std::string_viewprefix="",
unsignedintprecision=10,
boolexponential=false)const;
voiddump(std::string_viewprefix="",
unsignedintprecision=10,
boolexponential=false)const;
voidmakeNotReady();
boolisReady()const;
//Copyconstructor,moveconstructor,andassignmentoperators
public:
UnitQuaternion(constUnitQuaternion&other);
UnitQuaternion(UnitQuaternion&&other)noexcept;
UnitQuaternion&operator=(constUnitQuaternion&other);
UnitQuaternion&operator=(UnitQuaternion&&other)noexcept;
public:
constQuaterniond&asEigen()const;
constRotationMatrix&toRotationMatrix()const;
template<typenameeuler_system>EulerAngles<double,euler_system>toEulerAngles(){
returnEulerAngles<double,euler_system>(toRotationMatrix());
}
boolisIdentity(doubleepsilon=MATH_EPSILON)const;
voidsetIdentity();
booloperator==(constUnitQuaternion&other)const;
boolisApprox(constUnitQuaternion&other,doubleprec=MATH_EPSILON)const;
UnitQuaternionoperator*(constUnitQuaternion&other)const;
Vec3operator*(constVec3&vec)const;
SpatialVectoroperator*(constSpatialVector&vec)const;
UnitQuaternioninverse()const;
constEigen::Ref<constVec3>vec()const;
Eigen::AngleAxis<double>toAngleAxis()const;
RotationVectortoRotationVector()const;
constVec4&toVector4()const;
Mat33rotate(constMat33&mat)const;
Mat6nrotateLeft6N(constMat6n&mat)const;
MatrotateRightN6(constMat&mat)const;
Mat66rotate66(constMat66&mat)const;
Vec4omegaToRates(constVec3&omega,booloframe)const;
Mat33vectorRatesToOmegaMap(booloframe,doubleepsilon=MATH_EPSILON)const;
Mat33omegaToVectorRatesMap(booloframe)const;
Vec3omegaToScalarRateMap()const;
MatratesToOmegaMap(booloframe)const;
MatomegaToRatesMap(booloframe)const;
MatratesToRotVecRatesMap()const;
private:
void_setValues(boolrenormalize=false,boolskip_values_check=false);
void_isUnitNorm(doubleepsilon=MATH_EPSILON)const;
Quaterniond_quat=Quaterniond(1.0,0.0,0.0,0.0);
mutablebool_cached_rot_mat_flag=false;
mutableRotationMatrix_cached_rot_mat;
//bool_is_identity=true;
};
}//namespaceKarana::Math