public List <Point> DetermineRotationCenter(PolygonSide s, double angle, double sensitivity = 0.00001) { List <Point> sortedPoints = new List <Point>(); Point newPoint = hTranslation(hRotation(s.B, s.A, angle), s.A); if (ComparePoints(newPoint, s.closestA, sensitivity)) { // rotation center sortedPoints.Add(s.B); // rotation point sortedPoints.Add(s.A); return(sortedPoints); } else { // rotation center sortedPoints.Add(s.A); // rotation point sortedPoints.Add(s.B); return(sortedPoints); } }
public void GetPolygon(ref List <PolygonSide> tesalation, PolygonSide s, int p, int q, int iteration) { if (iteration == 0) { return; } Point o = new Point(0, 0); double angle = ConvertToDegrees((2 * Math.PI) / q); List <Point> polygonVertex = new List <Point>(); List <PolygonSide> polygonSides = new List <PolygonSide>(); // By default sensitivity List <Point> sortedPoints = DetermineRotationCenter(s, angle); Point rotatedPoint = new Point(); int counter = 0; Point rotationCenter = sortedPoints[0]; Point rotationPoint = sortedPoints[1]; polygonVertex.Add(rotationPoint); polygonVertex.Add(rotationCenter); // We need all points but p - 1 sides because we need to generate for PolygonSide // Two polyigon vertex are knows so we need p - 2 more while (counter < p - 2) { rotatedPoint = hTranslation(hRotation(rotationPoint, rotationCenter, angle), rotationCenter); // Check if point of polyigon belongs to poencare disk // New Polygon otherwise would be parcial in poencare disk if (FindDistance(rotatedPoint, o) > 1) { return; } polygonVertex.Add(rotatedPoint); rotationPoint = rotationCenter; rotationCenter = rotatedPoint; counter = counter + 1; } counter = 1; // Skip first side because we dont need it for a process while (counter < p) { PolygonSide polygonSide = new PolygonSide(); // p - 1 - beacuse counter starts from 0 // Check if it is last side od polygon (point) if (counter == p - 1) { polygonSide.closestA = polygonVertex[counter - 1]; polygonSide.A = polygonVertex[counter]; polygonSide.B = polygonVertex[0]; polygonSide.closestB = polygonVertex[1]; polygonSides.Add(polygonSide); counter = counter + 1; continue; } // p - 2 - beacuse counter starts from 0 // Check if it is second lastest side od polygon (point) if (counter == p - 2) { polygonSide.closestA = polygonVertex[counter - 1]; polygonSide.A = polygonVertex[counter]; polygonSide.B = polygonVertex[counter + 1]; polygonSide.closestB = polygonVertex[0]; polygonSides.Add(polygonSide); counter = counter + 1; continue; } polygonSide.closestA = polygonVertex[counter - 1]; polygonSide.A = polygonVertex[counter]; polygonSide.B = polygonVertex[counter + 1]; polygonSide.closestB = polygonVertex[counter + 2]; polygonSides.Add(polygonSide); counter = counter + 1; } tesalation.AddRange(polygonSides); foreach (PolygonSide side in polygonSides) { GetPolygon(ref tesalation, side, p, q, iteration - 1); } }
// p - number of sides of polygon // q - number of polyigons that meet at single vertex // Points added in context of OpenGL (added aditional z = 0 cordinate, added color) public void tGetInitialRegularPolygon(ref List <PolygonSide> tesalation, int p, int q, int iteration) { double s = Math.Sqrt((1 - Math.Tan(Math.PI / p) * Math.Tan(Math.PI / q)) / (1 + Math.Tan(Math.PI / p) * Math.Tan(Math.PI / q))); //s = 0.5; List <Point> points = new List <Point>(); List <PolygonSide> polygonSides = new List <PolygonSide>(); Point orgin = new Point(0, 0); Point newPoint = new Point(); int counter = 0; while (counter < p) { newPoint = hRotation(new Point(s, 0), orgin, (counter + 1) * (360 / p)); points.Add(newPoint); counter = counter + 1; } counter = 0; // points.Count == p while (counter < p) { PolygonSide polygonSide = new PolygonSide(); if (counter == 0) { polygonSide.closestA = points[points.Count - 1]; polygonSide.A = points[counter]; polygonSide.B = points[counter + 1]; polygonSide.closestB = points[counter + 2]; polygonSides.Add(polygonSide); counter = counter + 1; continue; } // p - 1 - beacuse counter starts from 0 // Check if it is last side od polygon (point) if (counter == p - 1) { polygonSide.closestA = points[counter - 1]; polygonSide.A = points[counter]; polygonSide.B = points[0]; polygonSide.closestB = points[1]; polygonSides.Add(polygonSide); counter = counter + 1; continue; } // p - 2 - beacuse counter starts from 0 // Check if it is second lastest side od polygon (point) if (counter == p - 2) { polygonSide.closestA = points[counter - 1]; polygonSide.A = points[counter]; polygonSide.B = points[counter + 1]; polygonSide.closestB = points[0]; polygonSides.Add(polygonSide); counter = counter + 1; continue; } polygonSide.closestA = points[counter - 1]; polygonSide.A = points[counter]; polygonSide.B = points[counter + 1]; polygonSide.closestB = points[counter + 2]; polygonSides.Add(polygonSide); counter = counter + 1; } tesalation.AddRange(polygonSides); foreach (PolygonSide side in polygonSides) { GetPolygon(ref tesalation, side, p, q, iteration); } }