00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023 #include "triplex.h"
00024 #include <cmath>
00025
00029 triplex::triplex(){
00030 }
00031
00035 triplex::triplex(float a, float b, float c):a(a), b(b), c(c){
00036 }
00037
00041 triplex triplex::operator=(const triplex& t){
00042 a = t.a;
00043 b = t.b;
00044 c = t.c;
00045 return *this;
00046 }
00047
00051 triplex::triplex(const triplex& t){
00052 a = t.a;
00053 b = t.b;
00054 c = t.c;
00055 }
00056
00060 triplex triplex::operator+(triplex& t){
00061 triplex newt;
00062 newt.a = a+t.a;
00063 newt.b = b+t.b;
00064 newt.c = c+t.c;
00065 return newt;
00066 }
00067
00071 triplex triplex::operator-(triplex& t){
00072 triplex newt;
00073 newt.a = a-t.a;
00074 newt.b = b-t.b;
00075 newt.c = c-t.c;
00076 return newt;
00077 }
00078
00082 triplex triplex::operator/(float f){
00083 triplex newt;
00084 if (f != 0){
00085 newt.a = a/f;
00086 newt.b = b/f;
00087 newt.c = c/f;
00088 }
00089 return newt;
00090 }
00091
00095 triplex triplex::operator*(float f){
00096 triplex newt;
00097 newt.a = a*f;
00098 newt.b = b*f;
00099 newt.c = c*f;
00100 return newt;
00101 }
00102
00106 triplex triplex::normalize(){
00107 triplex t(*this);
00108
00109 float norm = sqrt(t.norm2());
00110 return t/norm;
00111 }
00112
00116 triplex triplex::square(){
00117 triplex newt;
00118 newt.a = a*a-b*b-c*c;
00119 newt.b = 2*a*b - b*c;
00120 newt.c = 2*a*c + b*c;
00121 return newt;
00122 }
00126 float triplex::norm2(){
00127 return a*a + b*b + c*c;
00128 }
00129
00133 triplex triplex::rotateX(float f){
00134 triplex newt(a,
00135 b*cos(f) - c*sin(f),
00136 b*sin(f) + c*cos(f));
00137 return newt;
00138 }
00139
00140
00144 triplex triplex::rotateY(float f){
00145 triplex newt(a*cos(f) + c*sin(f),
00146 b,
00147 -a*sin(f) + c*cos(f)
00148 );
00149
00150 return newt;
00151 }
00152
00156 triplex triplex::rotateZ(float f){
00157 triplex newt(a*cos(f) - b*sin(f),
00158 a*sin(f) + b*cos(f),
00159 c);
00160
00161 return newt;
00162 }
00163
00167 float triplex::scalar(triplex& f){
00168 return f.a*a + f.b*b + f.c*c;
00169 }