gvsu/cs658/final/util/Vector.cc
josh 1d26118e32 added cross- and dot-products to util/Vector
git-svn-id: svn://anubis/gvsu@358 45c1a28c-8058-47b2-ae61-ca45b979098e
2009-01-16 18:14:01 +00:00

33 lines
726 B
C++

#include "Vector.h"
#include <iostream>
Vector::Vector()
{
m_array[0] = 0.0;
m_array[1] = 0.0;
m_array[2] = 0.0;
}
std::ostream & operator<<(std::ostream & out, const Vector & v)
{
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
return out;
}
/* Compute the dot-product of two vectors */
double operator%(const Vector & v1, const Vector & v2)
{
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
}
/* Compute the cross-product of two vectors */
Vector operator*(const Vector & v1, const Vector & v2)
{
Vector result;
result[0] = v1[1] * v2[2] - v1[2] * v2[1];
result[1] = v1[2] * v2[0] - v1[0] * v2[2];
result[2] = v1[0] * v2[1] - v1[1] * v2[0];
return result;
}