#include "header.h"
//Przypisanie wartości wprowadzonych do elementow kwaternionu
Quaternion::Quaternion(int a, int b, int c, int d)
{
Dfactor = d;
Afactor = a;
Bfactor = b;
Cfactor = c;
}
//Algebraiczne dodawanie dwoch kwaternionow
Quaternion Quaternion::operator+(Quaternion&q){
Quaternion q2(q.Afactor + this->Afactor, q.Bfactor + this->Bfactor, q.Cfactor + this->Cfactor, q.Dfactor + this->Dfactor);
return q2;
}
//Algebraiczne odejmowanie dwoch kwaternionow
Quaternion Quaternion::operator-(Quaternion&q){
Quaternion q2(q.Afactor - this->Afactor, q.Bfactor - this->Bfactor, q.Cfactor - this->Cfactor, q.Dfactor - this->Dfactor);
return q2;
}
//Algebraiczne dodawanie drugiego kwaternionu do pierwszego
Quaternion& Quaternion::operator+=(Quaternion&q){
this->Afactor += q.Afactor;
this->Bfactor += q.Bfactor;
this->Cfactor += q.Cfactor;
this->Dfactor += q.Dfactor;
return *this;
}
//Algebraiczne odejmowanie drugiego kwaternionu od pierwszego
Quaternion& Quaternion::operator-=(Quaternion&q){
this->Afactor -= q.Afactor;
this->Bfactor -= q.Bfactor;
this->Cfactor -= q.Cfactor;
this->Dfactor -= q.Dfactor;
return *this;
}
//Algebraiczne mnozenie kwaternionow
Quaternion Quaternion::operator*(Quaternion&q){
Quaternion q2(0,0,0,0);
q2.Afactor = q.Afactor * this->Dfactor + q.Dfactor * this->Afactor - q.Bfactor * this->Cfactor - q.Cfactor * this->Bfactor;
q2.Bfactor = q.Bfactor * this->Dfactor + q.Dfactor * this->Bfactor - q.Afactor * this->Cfactor - q.Cfactor * this->Afactor;
q2.Cfactor = q.Cfactor * this->Dfactor + q.Dfactor * this->Cfactor - q.Bfactor * this->Afactor - q.Afactor * this->Bfactor;
q2.Dfactor = q.Dfactor * this->Dfactor - q.Afactor * this->Afactor - q.Bfactor * this->Bfactor - q.Cfactor * this->Cfactor;
return q2;
}
//algebraiczne domnazanie kwaternionu drugiego do pierwszego
Quaternion& Quaternion::operator*=(Quaternion&q){
this->Afactor = q.Afactor * this->Dfactor + q.Dfactor * this->Afactor - q.Bfactor * this->Cfactor - q.Cfactor * this->Bfactor;
this->Bfactor = q.Bfactor * this->Dfactor + q.Dfactor * this->Bfactor - q.Afactor * this->Cfactor - q.Cfactor * this->Afactor;
this->Cfactor = q.Cfactor * this->Dfactor + q.Dfactor * this->Cfactor - q.Bfactor * this->Afactor - q.Afactor * this->Bfactor;
this->Dfactor = q.Dfactor * this->Dfactor - q.Afactor * this->Afactor - q.Bfactor * this->Bfactor - q.Cfactor * this->Cfactor;
return *this;
}
//Algebraiczne wyznaczanie modulu
double Quaternion::module(){
return sqrt(this->Afactor * this->Afactor + this->Bfactor * this->Bfactor + this->Cfactor * this->Cfactor + this->Dfactor * this->Dfactor);
}
//Wypisywanie kwaternionu w formie algebraicznej
std::ostream & operator <<(std::ostream &strm, Quaternion &q){
return strm << q.Afactor << "i + " << q.Bfactor << "j + " << q.Cfactor << "k + " << q.Dfactor;
}