1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
/*
Copyright (C) 2000 Matthew Danish
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include"vector.h"
#include<math.h>
#include"defines.h"
VectorClass::VectorClass() :
x(0),y(0),z(0)
{}
VectorClass::VectorClass(double _x,double _y,double _z) :
x(_x),y(_y),z(_z)
{}
VectorClass::VectorClass(double mag,double angle) {
x=mag*sin((MY_PI/180) * angle);
y=0;
z=mag*cos((MY_PI/180) * angle);
}
VectorClass::~VectorClass() {}
double VectorClass::X() {
return x;
}
double VectorClass::Y() {
return y;
}
double VectorClass::Z() {
return z;
}
double VectorClass::X(double _x) {
return (x=_x);
}
double VectorClass::Y(double _y) {
return (y=_y);
}
double VectorClass::Z(double _z) {
return (z=_z);
}
bool VectorClass::operator ==(VectorClass &v) {
if(x == v.x && y == v.y && z == v.z) return true;
else return false;
}
bool VectorClass::operator !=(VectorClass &v) {
return !(*this == v);
}
VectorClass operator -(VectorClass &a, VectorClass &b) {
VectorClass v(a.x - b.x, a.y - b.y, a.z - b.z);
return v;
}
double VectorClass::Magnitude() {
return sqrt(x*x+y*y+z*z);
}
VectorClass & VectorClass::operator +=(VectorClass &a) {
x+=a.X();
y+=a.Y();
z+=a.Z();
return *this;
}
double VectorClass::Dot(VectorClass &a) {
return (a.X() * X() + a.Y() * Y() + a.Z() * Z());
}
|