I assume that you want to create the same one-sided polygon coordinates that you can feed into your drawing program. I'm not sure which library you are using, so I will stick to lists of pairs of values:
import math def polygon(sides, radius=1, rotation=0, translation=None): one_segment = math.pi * 2 / sides points = [ (math.sin(one_segment * i + rotation) * radius, math.cos(one_segment * i + rotation) * radius) for i in range(sides)] if translation: points = [[sum(pair) for pair in zip(point, translation)] for point in points] return points
There is an honest cue ball, so I’ll talk about it. The basic approach is to sweep the circle and draw n equally spaced points on it. These will be the points of our polygon, starting from the 12-hour position.
The first thing to do is work out the angle (in radians) of each wedge from the center out. The total number of radians in the circle is 2 pi, so our value is 2 pi / n per segment.
After that, a little basic trigger gives us our points ( https://en.wikipedia.org/wiki/Trigonometry#Extending_the_definitions ). At this moment, we scale to our desired radius and are also able to compensate for the rotation by a fixed amount.
After that, we translate the values by a certain amount, because you probably want your polygon to be in the center of the screen, and not in the corner.
A few examples
print polygon(5)
As you can see, these are all floats, so you may have to grind them to integers before you can use them.
source share