From a80b4b146dc27e5e2e0b1ea11da56dc743233241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 9 Apr 2013 10:11:38 +0200 Subject: [PATCH] Math: write Vector2::cross() in terms of perpendicular() and dot(). --- src/Math/Vector2.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 4e7b17c00..11a6d4285 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -83,15 +83,16 @@ template class Vector2: public Vector<2, T> { /** * @brief 2D cross product * - * 2D version of cross product, equivalent to calling Vector3::cross() - * with Z coordinate set to `0` and extracting only Z coordinate from - * the result (X and Y coordinates are always zero). - * @f[ - * \boldsymbol a \times \boldsymbol b = a_xb_y - a_yb_x + * 2D version of cross product, also called perp-dot product, + * equivalent to calling Vector3::cross() with Z coordinate set to `0` + * and extracting only Z coordinate from the result (X and Y + * coordinates are always zero). @f[ + * \boldsymbol a \times \boldsymbol b = \boldsymbol a_\perp \cdot \boldsymbol b = a_xb_y - a_yb_x * @f] + * @see perpendicular(), dot(const Vector&, const Vector&) */ inline static T cross(const Vector2& a, const Vector2& b) { - return a.x()*b.y() - a.y()*b.x(); + return Vector<2, T>::dot(a.perpendicular(), b); } /** @copydoc Vector::Vector() */ @@ -129,7 +130,7 @@ template class Vector2: public Vector<2, T> { * Returns vector rotated 90° counterclockwise. @f[ * \boldsymbol v_\perp = \begin{pmatrix} -v_y \\ v_x \end{pmatrix} * @f] - * @see dot(const Vector&, const Vector&), operator-() const + * @see cross(), dot(const Vector&, const Vector&), operator-() const */ inline Vector2 perpendicular() const { return {-y(), x()}; }