#include "vector.h"
-#include <math.h> // For sqrt()
+#include <math.h> // For sqrt()
#include "mathconstants.h"
// Vector implementation
-Vector::Vector(double xx/*= 0*/, double yy/*= 0*/, double zz/*= 0*/): x(xx), y(yy), z(zz)
+Vector::Vector(double xx/*= 0*/, double yy/*= 0*/, double zz/*= 0*/): x(xx), y(yy), z(zz), b(0)
{
}
-Vector::Vector(Vector tail, Vector head): x(head.x - tail.x), y(head.y - tail.y), z(head.z - tail.z)
+Vector::Vector(Vector tail, Vector head): x(head.x - tail.x), y(head.y - tail.y), z(head.z - tail.z), b(0)
{
}
-Vector::Vector(const Vector &v): x(v.x), y(v.y), z(v.z)
+Vector::Vector(const Vector &v): x(v.x), y(v.y), z(v.z), b(v.b)
{
}
Vector Vector::operator=(Vector const v)
{
- x = v.x, y = v.y, z = v.z;
+ x = v.x, y = v.y, z = v.z, b = v.b;
return *this;
}
return sqrt((xx * xx) + (yy * yy) + (zz * zz));
}
+//
+// Convenience function
+//
+/*static*/ Vector Vector::Unit(Point p1, Point p2)
+{
+ return Vector(p1, p2).Unit();
+}
+
//
// Convenience function
//
return Vector(-v.y, v.x);
}
-/*static*/ double Vector::AngleBetween(Vector a, Vector b)
+/*static*/ double Vector::AngleBetween(Vector a1, Vector a2)
{
// This is done using the following formula:
// (a . b) = ||a|| ||b|| cos(theta)
// 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.
- if (a.isZero() || b.isZero())
+ if (a1.isZero() || a2.isZero())
return 0;
- return acos(a.Dot(b) / (a.Magnitude() * b.Magnitude()));
+ return acos(a1.Dot(a2) / (a1.Magnitude() * a2.Magnitude()));
+}
+
+/*static*/ Point Vector::Midpoint(Point p1, Point p2)
+{
+ return Point((p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0);
}