Exemplo n.º 1
0
    def angle_for_vertex(self, v: Vertex):
        """
        Returns plane angle at the given vertex v,
        or raises an Error if such vertex is not in the face
        """
        # p1 ---> p2
        # p1 ---> p3
        i = self.vertices.index(v)

        p1 = self.vertices[i]
        p2 = self.vertices[(i + 1) % len(self.vertices)]
        p3 = self.vertices[(i + 2) % len(self.vertices)]

        return vector_angle(vector_from_to(p1.pos, p2.pos),
                            vector_from_to(p1.pos, p3.pos))
Exemplo n.º 2
0
    def test_zero_angle(self):
        v1 = Vector3(0, 0, 3)
        v2 = Vector3(0, 0, 12)

        angle = vector_angle(v2, v1)
        self.assertEqual(angle, 0)
Exemplo n.º 3
0
    def test_180_angle(self):
        v1 = Vector3(1, 1, 3)
        v2 = Vector3(-1, -1, -3)

        angle = vector_angle(v2, v1)
        self.assertEqual(angle, math.pi)
Exemplo n.º 4
0
    def test_opposite_positive_angle(self):
        v1 = Vector3(0, 0, 3)
        v2 = Vector3(1, -3, 0)

        angle = vector_angle(v2, v1)
        self.assertEqual(angle, math.pi / 2)