A polygon is a plane shape (2D) with straight lines. It consists of vertices and edges.
A polygon is regular when all angles are equal and all sides are equal. For instance a regular pentagon consists of 5 vertices and 5 edges of equal size. The vertices of a regular pentagon are equally spread on a circle. This outside circle is called a circumcircle, and it connects all vertices (corner points) of the polygon. The radius of the circumcircle is also the radius of the polygon. We can use the trigonometric formulas to work out the (x,y) coordinates of each vertex of a regular pentagon. (See picture on the right).
Using this approach, we can use a Python script to calculate the (x,y) cooridnates of the 5 vertices of a regular pentagon and store them in a list of [x,y] sub-lists.
R = 150
for n in range(0,5):
x = R*math.cos(math.radians(90+n*72))
y = R*math.sin(math.radians(90+n*72))
A pentagram is a polygon that looks like a 5-pointed star. The outer vertices (points of the stars) form a regular pentagon. The inner vertices of the star also form a smaller “inner” regular pentagon.
We can hence use a similar approach to calculate the (x,y) coordinates of both “outer” and “inner” vertices of our pentagram.
We have completed the code to calculate the coordinates of a regular pentagon (using the code provided above) and have created a function called drawPolygon() that uses Python Turtle to draw a polygon on screen.
Adapt the above Python code to calculate the coordinates of all the vertices of a pentagram (star shape) and draw the pentagram on screen.
The output of your program should be as follows:
Use the shoelace algorithm to calculate the area of your pentagram.