Exemple #1
0
 def test_vector3d_sub(self):
     v1 = geometry.Vector3d(10, 10, 20)
     v2 = geometry.Vector3d(5, 3, 10)
     v_sum = v1 - v2
     self.assertEqual(v_sum.x, v1.x - v2.x)
     self.assertEqual(v_sum.y, v1.y - v2.y)
     self.assertEqual(v_sum.z, v1.z - v2.z)
Exemple #2
0
 def test_vector3d_add(self):
     v1 = geometry.Vector3d(10, 10, 20)
     v2 = geometry.Vector3d(5, 3, 10)
     v_sum = v1 + v2
     self.assertEqual(v_sum.x, v1.x + v2.x)
     self.assertEqual(v_sum.y, v1.y + v2.y)
     self.assertEqual(v_sum.z, v1.z + v2.z)
Exemple #3
0
    def test_convert_3d_to_2d(self):
        base1 = geometry.Vector3d(-1, -1, 0)
        base2 = geometry.Vector3d(-0.5, -0.5, 1)
        origin = geometry.Point3d(0.5, 0.5, 0)

        point = geometry.Point3d(-0.25, -0.25, 0.5)

        result = Projector._convert_3d_to_2d(origin, base1, base2, point)
        self.assertAlmostEqual(result.x, 0.5, delta=self.EPS)
        self.assertAlmostEqual(result.y, 0.5, delta=self.EPS)
Exemple #4
0
 def test_vector3d_rmul(self):
     v = geometry.Vector3d(10, 5, 20)
     k = 3
     scaled_v = k * v
     self.assertEqual(scaled_v.x, v.x * k)
     self.assertEqual(scaled_v.y, v.y * k)
     self.assertEqual(scaled_v.z, v.z * k)
Exemple #5
0
    def test_project_point_when_exist(self):
        view_vector = geometry.Vector3d(0, 0, 1)
        projector = Projector(view_vector, 90)
        point = geometry.Point3d(0, 0, 0.5)

        actual_projection = projector.project_point_on_view_plate(point)
        expected_projection = geometry.Point2d(0, 0)

        self.assertAlmostEqual(actual_projection.x, expected_projection.x, delta=self.EPS)
        self.assertAlmostEqual(actual_projection.y, expected_projection.y, delta=self.EPS)
Exemple #6
0
 def test_vector3d_length(self):
     v1 = geometry.Vector3d(1, 2, 3)
     length = v1.length()
     self.assertAlmostEqual(length, math.sqrt(14), geometry.EPS)
Exemple #7
0
 def test_vector3d_mixed_prod(self):
     v1 = geometry.Vector3d(1, 2, 3)
     v2 = geometry.Vector3d(5, 4, 3)
     v3 = geometry.Vector3d(1, 0, 2)
     prod = geometry.Vector3d.mixed_product(v1, v2, v3)
     self.assertEqual(prod, -18)
Exemple #8
0
 def test_vector3d_scalar_prod(self):
     v1 = geometry.Vector3d(10, 10, 20)
     v2 = geometry.Vector3d(5, 3, 10)
     prod = v1.scalar_prod(v2)
     self.assertEqual(prod, 280)