From 7cc953a44eff42220b2c7813db78610d51aa82be Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 11 Feb 2020 17:02:16 -0500 Subject: [PATCH] add extension method: Vector2.Rotate() GitOrigin-RevId: ee1e84ff188d5a3134dafb1f5150199682c4e063 --- Shared/Geometry.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Shared/Geometry.cs b/Shared/Geometry.cs index fb9bc94..b5a22e5 100644 --- a/Shared/Geometry.cs +++ b/Shared/Geometry.cs @@ -5,6 +5,16 @@ using System; namespace SemiColinGames { + public static class Geometry { + public static Vector2 Rotate(this Vector2 point, float angle) { + float cos = FMath.Cos(angle); + float sin = FMath.Sin(angle); + return new Vector2( + point.X * cos - point.Y * sin, + point.Y * cos + point.X * sin); + } + } + // Math functions that return floats rather than doubles, for convenience. public static class FMath { public const float PI = (float) Math.PI;