public static RegularPolygon CreateRegularPolygon(Drawing drawing, IList <IFigure> dependencies) { var result = new RegularPolygon() { Drawing = drawing, Dependencies = dependencies }; return(result); }
public static RegularPolygon CreateRegularPolygon(Drawing drawing, IList<IFigure> dependencies) { var result = new RegularPolygon() { Drawing = drawing, Dependencies = dependencies }; return result; }
/// <summary> /// Parse a regular polygon. (Currently only equilateral triangles) /// </summary> /// <param name="rgon">The regular polygon to parse.</param> private void ParseRegularPolygon(RegularPolygon rgon) { // Acquire the implicit center of the regular polygon IPoint center = rgon.Dependencies.FindPoint(rgon.Center, 0); IPoint vertex = rgon.Dependencies.FindPoint(rgon.Vertex, 0); int numSides = rgon.NumberOfSides; // // Genereate vertex points knowing that the polygon is regular // IPoint[] pts = new IPoint[numSides]; double radius = Math.Distance(vertex.Coordinates.X, center.Coordinates.X, vertex.Coordinates.Y, center.Coordinates.Y); double initAngle = Math.GetAngle(new System.Windows.Point(center.Coordinates.X, center.Coordinates.Y), new System.Windows.Point(vertex.Coordinates.X, vertex.Coordinates.Y)); double increment = Math.DOUBLEPI / numSides; // Vertex point generation and parsing. for (int i = 0; i < numSides - 1; i++) { double angle = initAngle + (i + 1) * increment; double X = center.Coordinates.X + radius * System.Math.Cos(angle); double Y = center.Coordinates.Y + radius * System.Math.Sin(angle); System.Windows.Point newPt = new System.Windows.Point(X, Y); pts[i] = rgon.Dependencies.FindPoint(newPt, 0); if (pts[i] == null) pts[i] = Factory.CreateFreePoint(drawing, newPt); Parse(pts[i] as IFigure); } pts[numSides - 1] = vertex; Parse(pts[numSides - 1] as IFigure); // // Generate sides from vertices // List<GeometryTutorLib.ConcreteAST.Segment> tutorSegments = new List<GeometryTutorLib.ConcreteAST.Segment>(); for (int i = 0; i < numSides; i++) { int j = (i + 1) % 3; tutorSegments.Add(new GeometryTutorLib.ConcreteAST.Segment(uiToEngineMap[pts[i]] as Point, uiToEngineMap[pts[j]] as Point)); } definedSegments.AddRange(tutorSegments); GeometryTutorLib.ConcreteAST.Polygon newPoly = null; switch(numSides) { case 3: newPoly = new EquilateralTriangle(tutorSegments); polygons[GeometryTutorLib.ConcreteAST.Polygon.TRIANGLE_INDEX].Add(newPoly); break; case 4: Quadrilateral newQuad = Quadrilateral.GenerateQuadrilateral(tutorSegments); if (newQuad != null) { newPoly = new Rhombus(newQuad); polygons[GeometryTutorLib.ConcreteAST.Polygon.QUADRILATERAL_INDEX].Add(newPoly); } break; case 5: case 6: case 7: case 8: case 9: case 10: break; default: break; } if (newPoly != null) uiToEngineMap.Add(rgon, newPoly); }