X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvector.cpp;h=e992bbffd53aa5496bffde85c0ff6b543f4891fd;hb=8ab4e08bd78cb5b07f069e3e6c5bf76944cb14fa;hp=da0d4c557aae2fe4e68b5df17d8cf0d4ce5f0ccf;hpb=9f6ad3fe0b9cb30115a5d38e8af3aebed0d70c08;p=architektonas diff --git a/src/vector.cpp b/src/vector.cpp index da0d4c5..e992bbf 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -1,7 +1,7 @@ // // vector.cpp: Various structures used for 3 dimensional imaging // -// by James L. Hammons +// by James Hammons // (C) 2006 Underground Software // // JLH = James L. Hammons @@ -25,6 +25,10 @@ Vector::Vector(double xx/*= 0*/, double yy/*= 0*/, double zz/*= 0*/): x(xx), y(y { } +Vector::Vector(Vector head, Vector tail): x(head.x - tail.x), y(head.y - tail.y), z(head.z - tail.z) +{ +} + Vector Vector::operator=(Vector const v) { x = v.x, y = v.y, z = v.z; @@ -129,6 +133,35 @@ Vector& Vector::operator+=(double const v) return *this; } +// Vector - vector, self assigned + +Vector& Vector::operator-=(Vector const v) +{ + x -= v.x, y -= v.y, z -= v.z; + + return *this; +} + +// Vector - constant, self assigned + +Vector& Vector::operator-=(double const v) +{ + x -= v, y -= v, z -= v; + + return *this; +} + +// Check for equality +bool Vector::operator==(Vector const v) +{ + return (x == v.x && y == v.y && z == v.z ? true : false); +} + +// Check for inequality +bool Vector::operator!=(Vector const v) +{ + return (x != v.x || y != v.y || z != v.z ? true : false); +} Vector Vector::Unit(void) { @@ -169,3 +202,11 @@ double Vector::Dot(Vector v1, Vector v2) { return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z); } + +double Vector::Magnitude(Vector v1, Vector v2) +{ + double xx = v1.x - v2.x; + double yy = v1.y - v2.y; + double zz = v1.z - v2.z; + return sqrt(xx * xx + yy * yy + zz * zz); +}