Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Vector3.h

Go to the documentation of this file.
00001 // Vector3.h: interface for the Vector3 class.
00002 //
00004 
00005 #ifndef VECTOR3_H
00006 #define VECTOR3_H
00007 
00008 #include "ThyrixParameters.h"
00009 #include <assert.h>
00010 
00013 class Vector3  {
00014 public:
00016    Vector3()                                 { x=0.0; y=0.0; z=0.0;  }
00018    Vector3(real x, real y, real z)           { this->x=x; this->y=y; this->z=z; }
00020    virtual ~Vector3()                        {}
00021 
00022    real x;
00023    real y;
00024    real z;
00025 
00027    void setToZero()                          { x=0.0; y=0.0; z=0.0;  }
00028 
00030    void setXYZ(real x, real y, real z)       { this->x=x; this->y=y; this->z=z; }
00031 
00033    void setElement(int i, real value){
00034       assert(i>=1 && i<=3);
00035       if (i==1)
00036          x=value;
00037       else if (i==2)
00038          y=value;
00039       else
00040          z=value;
00041    }
00042    
00044    real getModule()                          { return sqrt(x*x+y*y+z*z); }
00045 
00047    real getSquaredModule()                   { return x*x+y*y+z*z; }
00048 
00053    void rotate(real alpha) {
00054       real yOld=y;
00055       real c=cos(alpha);
00056       real s=sin(alpha);
00057       y=y*c-z*s;
00058       z=yOld*s+z*c;
00059    }
00060    
00061 
00063    real operator[](int i){
00064       assert(i>=0 && i<=2);
00065       if (i==0)
00066          return x;
00067       else if (i==1)
00068          return y;
00069       else return z;
00070    }
00071 
00072    Vector3& operator+=(const Vector3& v)  { x+=v.x; y+=v.y; z+=v.z; return *this; }
00073    Vector3& operator-=(const Vector3& v)  { x-=v.x; y-=v.y; z-=v.z; return *this; }
00074    Vector3& operator*=(const real r)      { x*=r; y*=r; z*=r; return *this; }
00075    Vector3& operator/=(const real r)      { assert(r!=0.0); x/=r; y/=r; z/=r; return *this; }
00076 
00077 };
00078 
00079 #endif //VECTOR3_H

Thyrix homepageUsers' guide

(C) Arxia 2004-2005