Program Listing for File UnitQuaternion.h

Program Listing for File UnitQuaternion.h#

Return to documentation for file (include/Karana/Math/UnitQuaternion.h)

/*
*Copyright(c)2024-2025KaranaDynamicsPtyLtd.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<iostream>
#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::stringtypeString()const{return"UnitQuaternion";}

std::stringdumpString(conststd::string&prefix="",
unsignedintprecision=10,
boolexponential=false)const;

voiddump(conststd::string&prefix="",
unsignedintprecision=10,
boolexponential=false)const;

voiduninitialize();

boolisInitialized()const;

//Copyconstructor,moveconstructor,andassignmentoperators
public:
UnitQuaternion(constUnitQuaternion&other);

UnitQuaternion(constUnitQuaternion&&other)noexcept;

UnitQuaternion&operator=(constUnitQuaternion&other);

UnitQuaternion&operator=(constUnitQuaternion&&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{return_quat==other._quat;}

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{returnEigen::AngleAxis<double>(_quat);}

RotationVectortoRotationVector()const;

constVec4&toVector4()const;

Mat33rotate(constMat33&mat)const;

Mat6nrotateLeft6N(constMat6n&mat)const;

MatrotateRightN6(constMat&mat)const;

Mat66rotate66(constMat66&mat)const;

Vec4omega2rates(constVec3&omega,booloframe)const;

Mat33vectorRates2omegaMap(booloframe,doubleepsilon=MATH_EPSILON)const;

Mat33omega2vectorRatesMap(booloframe)const;

Vec3omega2scalarRateMap()const;

Matrates2omegaMap(booloframe)const;

Matomega2ratesMap(booloframe)const;

Matrates2rotvecratesMap()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