//\r
// vector.cpp: Various structures used for 3 dimensional imaging\r
//\r
-// by James L. Hammons\r
+// by James Hammons\r
// (C) 2006 Underground Software\r
//\r
// JLH = James L. Hammons <jlhamm@acm.org>\r
{\r
}\r
\r
+Vector::Vector(Vector head, Vector tail): x(head.x - tail.x), y(head.y - tail.y), z(head.z - tail.z)\r
+{\r
+}\r
+\r
Vector Vector::operator=(Vector const v)\r
{\r
x = v.x, y = v.y, z = v.z;\r
return *this;\r
}\r
\r
+// Vector - vector, self assigned\r
+\r
+Vector& Vector::operator-=(Vector const v)\r
+{\r
+ x -= v.x, y -= v.y, z -= v.z;\r
+\r
+ return *this;\r
+}\r
+\r
+// Vector - constant, self assigned\r
+\r
+Vector& Vector::operator-=(double const v)\r
+{\r
+ x -= v, y -= v, z -= v;\r
+\r
+ return *this;\r
+}\r
+\r
+// Check for equality\r
+bool Vector::operator==(Vector const v)\r
+{\r
+ return (x == v.x && y == v.y && z == v.z ? true : false);\r
+}\r
+\r
+// Check for inequality\r
+bool Vector::operator!=(Vector const v)\r
+{\r
+ return (x != v.x || y != v.y || z != v.z ? true : false);\r
+}\r
\r
Vector Vector::Unit(void)\r
{\r
{\r
return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);\r
}\r
+\r
+double Vector::Magnitude(Vector v1, Vector v2)\r
+{\r
+ double xx = v1.x - v2.x;\r
+ double yy = v1.y - v2.y;\r
+ double zz = v1.z - v2.z;\r
+ return sqrt(xx * xx + yy * yy + zz * zz);\r
+}\r