# An Example of a C++ class Implementation Of Euler Angles

As a scientific programmer one of the thing that I like with C++ is the overload operator.

Matrix A,B,C and then do the math operation A=B*C. With overload you can do that. This way you can model mathematical operation naturally. As a user what you with such rotation matrice is the support of the multiply operation.

Object oriented is about modeling type that match real world entity. In scientific programming math entity are matrices, scalar field and … With operator overloading you can represent those type naturally and write code that is close as you were writing it manually. That’s a rally nice feature!!
I present a case of the Euler angles (rotation matrices that are used in physics 3D or math 3d to animate rigid body for example). In the example with the Euler angles, there is a set of operations defined in class for multiplying rotation matrices. They are represented by operator* which allowed user or programmer to write code as the one above.

``````
namespace Sfx {
namespace Mth {

// _________________________________________________________
//
class EulerAngles
{
public:
typedef double Scalar;

//
// Ctor summary
//

// default ctor
EulerAngles()
: fPhi  ( 0.0),
fTheta( 0.0),
fPsi  ( 0.0)
{}

// ...
EulerAngles( Scalar phi, Scalar theta, Scalar psi )
: fPhi(phi),
fTheta(theta),
fPsi(psi)
{ Rectify();}

// ...
template
EulerAngles( IT begin, IT end) { SetComponents( begin, end); }

// NOTE:
// The compiler-generated copy ctor, copy assignment, and dtor are OK.

void Rectify();

//
// ======== Construction From other Rotation Forms ==================
//

explicit EulerAngles( const Rotation3D & r)  { Mth::convert( r, *this);}
explicit EulerAngles( const Quaternion & q)  { Mth::convert( q, *this);}
explicit EulerAngles( const AxisAngle  & a ) { Mth::convert( a, *this);}
explicit EulerAngles( RotationZ const  & r ) { Mth::convert( r, *this);}
explicit EulerAngles( RotationY const  & r ) { Mth::convert( r, *this);}
explicit EulerAngles( RotationX const  & r ) { Mth::convert( r, *this);}

EulerAngles &
operator = ( Rotation3D const  & r ) { return operator= ( EulerAngles(r)); }

EulerAngles &
operator = ( AxisAngle const & a ) { return operator= ( EulerAngles(a)); }

EulerAngles &
operator = ( Quaternion const  & q ) {return operator= ( EulerAngles(q)); }

EulerAngles &
operator = ( RotationZ const & r ) { return operator= ( EulerAngles(r)); }

EulerAngles &
operator = ( RotationY const & r ) { return operator= ( EulerAngles(r)); }

EulerAngles &
operator = ( RotationX const & r ) { return operator= ( EulerAngles(r)); }

.....
//
// ========= Multi-Rotation Operations ===============
//

EulerAngles operator * ( const Rotation3D  & r) const;
EulerAngles operator * ( const AxisAngle   & a) const;
EulerAngles operator * ( const EulerAngles & e) const;
EulerAngles operator * ( const Quaternion  & q) const;
EulerAngles operator * ( const RotationX  & rx) const;
EulerAngles operator * ( const RotationY  & ry) const;
EulerAngles operator * ( const RotationZ  & rz) const;

// _____________________________________________
//
template
EulerAngles & operator *= ( const R & r) { return *this = (*this)*r;}

...
};
}}

``````
0 replies
{"ft_lang_label":"__label__en","ft_lang_prob":0.5567704,"math_prob":0.9620145,"size":3245,"snap":"2021-43-2021-49","text_gpt3_token_len":770,"char_repetition_ratio":0.25300834,"word_repetition_ratio":0.15678777,"special_character_ratio":0.31710324,"punctuation_ratio":0.18023255,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9944285,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-04T17:11:27Z\",\"WARC-Record-ID\":\"<urn:uuid:009c78ab-c308-401f-8718-bb2c97756cb3>\",\"Content-Length\":\"50247\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0f6f76f2-83d9-447f-b88b-327e4f78e7d3>\",\"WARC-Concurrent-To\":\"<urn:uuid:90be2d9c-60df-451e-aad5-35bb40c2779f>\",\"WARC-IP-Address\":\"199.244.79.76\",\"WARC-Target-URI\":\"http://elligno.com/an-example-of-a-c-class-implementation-of-euler-angles/\",\"WARC-Payload-Digest\":\"sha1:VCTG4EPQKCPWUXA5K6CKDR3BLQLXBJP6\",\"WARC-Block-Digest\":\"sha1:CVKKVDB2PDQQFDHHTHHUYKDZWBCNTLOX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964362999.66_warc_CC-MAIN-20211204154554-20211204184554-00393.warc.gz\"}"}