X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvector.cpp;h=58228ca39f75a7cfe9bb1b834dd8f19af4d24bf0;hb=f19a3a172c425b7fcc5a648a94870f0247c6be89;hp=da0d4c557aae2fe4e68b5df17d8cf0d4ce5f0ccf;hpb=9f6ad3fe0b9cb30115a5d38e8af3aebed0d70c08;p=architektonas diff --git a/src/vector.cpp b/src/vector.cpp index da0d4c5..58228ca 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -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,24 @@ 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; +} + Vector Vector::Unit(void) { @@ -169,3 +191,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); +}