add Vector2.Rotate methods

main
cosmonaut 2022-08-03 16:15:47 -07:00
parent 9c8ec7ad5a
commit 9cd6e6cc7b
2 changed files with 26 additions and 0 deletions

View File

@ -674,6 +674,19 @@ namespace MoonWorks.Math.Fixed
}
}
/// <summary>
/// Rotates a Vector2 by an angle.
/// </summary>
/// <param name="vector">The vector to rotate.</param>
/// <param name="angle">The angle in radians.</param>
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

View File

@ -1088,6 +1088,19 @@ namespace MoonWorks.Math.Float
}
}
/// <summary>
/// Rotates a Vector2 by an angle.
/// </summary>
/// <param name="vector">The vector to rotate.</param>
/// <param name="angle">The angle in radians.</param>
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