From 9cd6e6cc7bbe9604d27ca0491398628c8ce4c021 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 3 Aug 2022 16:15:47 -0700 Subject: [PATCH] add Vector2.Rotate methods --- src/Math/Fixed/Vector2.cs | 13 +++++++++++++ src/Math/Float/Vector2.cs | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Math/Fixed/Vector2.cs b/src/Math/Fixed/Vector2.cs index c2615541..be63811c 100644 --- a/src/Math/Fixed/Vector2.cs +++ b/src/Math/Fixed/Vector2.cs @@ -674,6 +674,19 @@ namespace MoonWorks.Math.Fixed } } + /// + /// Rotates a Vector2 by an angle. + /// + /// The vector to rotate. + /// The angle in radians. + public static Vector2 Rotate(Vector2 vector, Fix64 angle) + { + return new Vector2( + vector.X * Fix64.Cos(angle) - vector.Y * Fix64.Sin(angle), + vector.X * Fix64.Sin(angle) + vector.Y * Fix64.Cos(angle) + ); + } + #endregion #region Public Static Operators diff --git a/src/Math/Float/Vector2.cs b/src/Math/Float/Vector2.cs index e9cffb70..e4e52be7 100644 --- a/src/Math/Float/Vector2.cs +++ b/src/Math/Float/Vector2.cs @@ -1088,6 +1088,19 @@ namespace MoonWorks.Math.Float } } + /// + /// Rotates a Vector2 by an angle. + /// + /// The vector to rotate. + /// The angle in radians. + public static Vector2 Rotate(Vector2 vector, float angle) + { + return new Vector2( + vector.X * (float) System.Math.Cos(angle) - vector.Y * (float) System.Math.Sin(angle), + vector.X * (float) System.Math.Sin(angle) + vector.Y * (float) System.Math.Cos(angle) + ); + } + #endregion #region Public Static Operators