X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvector.cpp;h=57f49fbb8b1d4bc7ae1566c91cdb58586691895f;hb=eb39f1bb5e6518c5dc4f4dbd3c88912a97192e95;hp=23b429902c2b22b892e25f8ab9cbb57813981f4c;hpb=84fc4387b9a6051819da5c9ed688de1ec372c7f7;p=architektonas diff --git a/src/vector.cpp b/src/vector.cpp index 23b4299..57f49fb 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -194,7 +194,8 @@ Vector Vector::Unit(void) { double mag = Magnitude(); - // If the magnitude of the vector is zero, then the Unit vector is undefined... + // If the magnitude of the vector is zero, then the Unit vector is + // undefined... if (mag == 0) return Vector(0, 0, 0); @@ -204,17 +205,17 @@ Vector Vector::Unit(void) double Vector::Magnitude(void) { - return sqrt(x * x + y * y + z * z); + return sqrt((x * x) + (y * y) + (z * z)); } double Vector::Angle(void) { - // acos returns a value between zero and PI, which means we don't know which - // quadrant the angle is in... Though, if the y-coordinate of the vector is - // negative, that means that the angle is in quadrants III - IV. + // acos returns a value between zero and TAU/2, which means we don't know + // which quadrant the angle is in... However, if the y-coordinate of the + // vector is negative, that means that the angle is in quadrants III - IV. double rawAngle = acos(Unit().x); - double correctedAngle = (y < 0 ? (2.0 * PI) - rawAngle : rawAngle); + double correctedAngle = (y < 0 ? TAU - rawAngle : rawAngle); return correctedAngle; } @@ -285,10 +286,10 @@ bool Vector::isZero(double epsilon/*= 1e-6*/) // This is done using the following formula: // (a . b) = ||a|| ||b|| cos(theta) // However, have to check for two degenerate cases, where a = cb: - // 1, if c > 0, theta = 0; 2, if c < 0, theta = 180°. + // 1) if c > 0, theta = 0; 2) if c < 0, theta = 180°. // Also, the vectors a & b have to be non-zero. // Also, have to check using an epsilon because acos will not return an - // exact value if the vectors are orthogonal + // exact value if the vectors are orthogonal. if (a.isZero() || b.isZero()) return 0;