*** empty log message ***

This commit is contained in:
jiri 2019-12-30 15:41:36 +00:00
parent 45bdb8c94f
commit 31c724ad27
2 changed files with 26 additions and 0 deletions

View File

@ -17,5 +17,19 @@
*/ */
#include "quaternion.h" #include "quaternion.h"
#include <math.h>
template<>
double Quaternion<double>::norm(void) const
{
return sqrt(this->normsqr());
}
template<>
float Quaternion<float>::norm(void) const
{
return sqrtf(this->normsqr());
}

View File

@ -19,6 +19,7 @@
#define _QUATERNION_H_ #define _QUATERNION_H_
#include <stdlib.h> #include <stdlib.h>
#include <iostream>
template <typename T> template <typename T>
class Quaternion class Quaternion
@ -32,6 +33,10 @@ public:
//compiler generates default copy constructor and assignment operator //compiler generates default copy constructor and assignment operator
//formal indexing
const T operator[](const int i) const {return this->q[i];};
T operator[](const int i) {return this->q[i];};
//operations of quaternions with scalars //operations of quaternions with scalars
Quaternion& operator=(const T x) {q[0]=x; memset(&q[1],0,3*sizeof(T)); return *this;}; //quaternion from real Quaternion& operator=(const T x) {q[0]=x; memset(&q[1],0,3*sizeof(T)); return *this;}; //quaternion from real
Quaternion& operator+=(const T rhs) {this->q[0]+=rhs; return *this;}; Quaternion& operator+=(const T rhs) {this->q[0]+=rhs; return *this;};
@ -58,8 +63,15 @@ public:
this->q[0]*rhs.q[3]+this->q[3]*rhs.q[0]+this->q[1]*rhs.q[2]-this->q[2]*rhs.q[1] this->q[0]*rhs.q[3]+this->q[3]*rhs.q[0]+this->q[1]*rhs.q[2]-this->q[2]*rhs.q[1]
); );
}; };
Quaternion& conjugateme(void) {q[1] = -q[1]; q[2] = -q[2]; q[3] = -q[3]; return *this;}
Quaternion conjugate(void) const {return Quaternion(*this).conjugateme();}
T normsqr(void) const {return q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];};
T norm(void) const;
Quaternion inverse(void) const {return Quaternion(*this).conjugateme()/this->normsqr();};
const Quaternion operator/(const Quaternion &rhs) const {return *this * rhs.inverse();};
}; };
//stream I/O //stream I/O
template <typename T> template <typename T>
std::istream& operator>>(std::istream &s, Quaternion<T> &x) std::istream& operator>>(std::istream &s, Quaternion<T> &x)