def __init__(self, num_sides, radius): GPolygon.__init__(self) dx = -radius dy = 0 self.addVertex(dx, dy) da = 360 / num_sides edge = math.sin(da / 2 * math.pi / 180) * radius * 2 angle = 0 for i in range(num_sides): self.addPolarEdge(edge, angle) angle -= da
def __init__(self, nSides, radius): ''' Creates a regular polygon with its reference point at the center. The nSides parameter indicates the number of sides and radius parameter indicates the distance from the reference point to any vertex. ''' GPolygon.__init__(self) edge = 2 * radius * math.sin((math.pi / nSides)) d_ang = 360 / nSides self.addVertex(edge / 2, radius) angle = 180 for i in range(nSides): self.addPolarEdge(edge, angle) angle -= d_ang
def __init__(self, nSides, radius): """ Initializes the Regular Polygon of the given perameters. The reference point is the center of the shape. """ GPolygon.__init__(self) self.nSides = nSides self.radius = radius theta = radians(360 / self.nSides) interiorTheta = radians(((self.nSides - 2) * 180) / self.nSides) sideLen = 2 * self.radius * sin(theta / 2) self.addVertex(-sideLen / 2, self.radius * cos(theta / 2)) newTheta = 0 for i in range(self.nSides - 1): self.addPolarEdge(sideLen, degrees(newTheta)) newTheta += (pi - interiorTheta)