using System.Collections.Generic;
public static void Main()
Traversal t = new Traversal(0, 5);
List<Vector2> points = new List<Vector2>();
Console.WriteLine(t.CartesianPoint());
Iteration(tt, 0, points);
foreach(Vector2 p in points)
Console.WriteLine(p.X + ", " + p.Y);
public static void Iteration(Traversal t, int depth, List<Vector2> points)
points.Add(new Traversal(0,5).CartesianPoint());
Iterate(t, depth, depth, points);
public static void Iterate(Traversal t, int startDepth, int depth, List<Vector2> points)
points.Add(t.CartesianPoint());
for (int i = 1; i <= 5; i++)
Iterate(t, startDepth, depth - 1, points);
public float sideLength = 1;
public int startRotation;
public List<int> sideNumbers = new List<int>();
public Traversal(int startRotation, int polySides)
this.startRotation = startRotation;
this.polySides = polySides;
apothem = (float)(sideLength / (2 * Math.Tan(DegToRad(180.0f / polySides))));
theta = 360.0f / polySides;
public void Traverse(int side)
if (side <= 5 && side > 0)
sideNumbers.RemoveAt(sideNumbers.Count - 1);
public Vector2 CartesianPoint()
for (int i = 0; i < sideNumbers.Count; i++)
x += (1 - 2 * rot) * (2 * apothem * (float)Math.Sin(DegToRad(theta * sideNumbers[i] - theta / 2.0f)));
y += (1 - 2 * rot) * (2 * apothem * (float)Math.Cos(DegToRad(theta * sideNumbers[i] - theta / 2.0f)));
x = (float)Math.Round(x, 4);
y = (float)Math.Round(y, 4);
public static float DegToRad(float degrees)
return degrees * (float)(Math.PI/180.0f);