diff --git a/Engine.Physics2D/Primitives/Shape.cs b/Engine.Physics2D/Primitives/Shape.cs index 5dbc804..5aa4c10 100644 --- a/Engine.Physics2D/Primitives/Shape.cs +++ b/Engine.Physics2D/Primitives/Shape.cs @@ -12,6 +12,22 @@ public record Shape(IList Vertices) : IEnumerable public static Shape CreateCopy(Shape shape) => new(new List(shape.Vertices)); + public static Shape CreateNgon(int vertexCount) => CreateNgon(vertexCount, Vector2D.Up); + public static Shape CreateNgon(int vertexCount, Vector2D positionToRotate) + { + if (vertexCount < 3) + throw new System.ArgumentException($"{nameof(vertexCount)} must have a value of more than 2."); + + List vertices = new(vertexCount); + + float radiansPerVertex = 360f / vertexCount * Math.DegreeToRadian; + + for (int i = 0; i < vertexCount; i++) + vertices.Add(positionToRotate.Rotate(i * radiansPerVertex)); + + return new(vertices); + } + public static Triangle GetSuperTriangle(Shape shape) { float minX = float.MaxValue, minY = float.MaxValue;