C:/sources/c++/buddhabrot/buddhabrot/triplex.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2010 Pierre SCHWARTZ
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
00005 documentation files (the "Software"), to deal in the Software without restriction, including without 
00006 limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
00007 of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 
00008 conditions: The above copyright notice and this permission notice shall be included in all copies or 
00009 substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00010 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
00011 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
00012 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 
00013 OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
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 }

Generated on Fri Feb 26 21:07:52 2010 for BuddhaBrot by  doxygen 1.4.6-NO