def orientation(self, theta=0.0): '''Retorna um vetor unitário na direção em que o objeto está orientado. Pode aplicar um ângulo adicional a este vetor fornecendo o parâmetro _theta.''' theta += self._theta return Vec2(cos(theta), sin(theta))
def _vertices(self, N, length, pos): self.length = length alpha = pi / N theta = 2 * alpha b = length / (2 * sin(alpha)) P0 = Vec2(b, 0) pos = Vec2(*pos) return [(P0.rotate(n * theta)) + pos for n in range(N)]
def rotate(self, theta): super(Poly, self).rotate(theta) # Realiza a matriz de rotação manualmente para melhor performance cos_t, sin_t = cos(theta), sin(theta) X, Y = self._pos for v in self.vertices: x = v.x - X y = v.y - Y v.x = cos_t * x - sin_t * y + X v.y = cos_t * y + sin_t * x + Y self._xmin = min(pt.x for pt in self.vertices) self._xmax = max(pt.x for pt in self.vertices) self._ymin = min(pt.y for pt in self.vertices) self._ymax = max(pt.y for pt in self.vertices)