From wikipedia:
the cross product is a binary operation on two vectors in a three-dimensional Euclidean space that results in another vector which is perpendicular to the plane containing the two input vectors.
Given that the definition is only defined in three (or seven, one and zero) dimensions, how does one calculate the cross product of two 2d vectors?
I have seen two implementations. One returns a new vector (but only accepts a single vector), the other returns a scalar (but is a calculation between two vectors).
Implementation 1 (returns a scalar):
float CrossProduct(const Vector2D & v1, const Vector2D & v2) const
{
return (v1.X*v2.Y) - (v1.Y*v2.X);
}
Implementation 2 (returns a vector):
Vector2D CrossProduct(const Vector2D & v) const
{
return Vector2D(v.Y, -v.X);
}
Why the varying implementations? What would I use the scalar implementation for? What would I use the vector implementation for?
The reason I ask is because I'm writing a Vector2D class myself and don't know which method to use.
x' = x cos θ - y sin θ
andy' = x sin θ + y cos θ
. Another variation of this implementation would be toreturn Vector2D(-v.Y, v.X);
which is rotate v by +90 degrees. – legends2kN-1
operands forN
dimensions. – Tim Čas