Add cross product.

This commit is contained in:
2019-08-04 23:29:56 -07:00
parent e157ee61e6
commit 3a5dd0490c
2 changed files with 44 additions and 2 deletions

View File

@@ -15,6 +15,7 @@
namespace wr {
namespace geom {
/**
* Vector provides a standard interface for dimensionless fixed-size
* vectors. Once instantiated, they cannot be modified. Note that while
@@ -203,6 +204,24 @@ public:
}
/**
* Compute the cross product of two vectors. This is only defined
* over three-dimensional vectors.
* @param other Another 3D vector.
* @return The cross product vector.
*/
Vector
cross(const Vector<T, N> &other)
{
assert(N == 3);
return Vector<T, N> {
(this->arr[1] * other.arr[2]) - (other.arr[1] * this->arr[2]),
-((this->arr[0] * other.arr[2]) - (other.arr[0] * this->arr[2])),
(this->arr[0] * other.arr[1]) - (other.arr[0] * this->arr[1])
};
}
/**
* Perform vector addition with another vector.
* @param other The vector to be added.