Пример #1
0
    def test_get_central_projection_when_exists(self):
        center = geometry.Point3d(-2, 1, 3)
        point = geometry.Point3d(-1, 0, 5)
        plate = geometry.Plate3d(1, 2, 3, -10)

        result = Projector._get_central_projection_on_plate(center, point, plate)

        to_result = center.get_vector_to(result)
        to_point = center.get_vector_to(point)

        self.assertAlmostEqual(
            to_result.y * to_point.z - to_result.z * to_point.y, 0,
            delta=self.EPS)
        self.assertAlmostEqual(
            to_result.x * to_point.z - to_result.z * to_point.x, 0,
            delta=self.EPS)
        self.assertAlmostEqual(
            to_result.x * to_point.y - to_result.y * to_point.x, 0,
            delta=self.EPS)

        self.assertAlmostEqual(
            plate.a * result.x + 
            plate.b * result.y + 
            plate.c * result.z + 
            plate.d, 0, delta=self.EPS)
Пример #2
0
    def test_get_central_projection_when_parallel(self):
        center = geometry.Point3d(0, 0, 0)
        point = geometry.Point3d(1, 0, 0)
        plate = geometry.Plate3d(0, 0, 1, 1)

        result = Projector._get_central_projection_on_plate(center, point, plate)

        self.assertIsNone(result)
Пример #3
0
    def test_get_central_projection_none_when_opposite(self):
        center = geometry.Point3d(0, 0, 0)
        point = geometry.Point3d(-1, 0, 5)
        plate = geometry.Plate3d(1, 2, 3, 10)

        result = Projector._get_central_projection_on_plate(center, point, plate)

        self.assertIsNone(result)
Пример #4
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)
Пример #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)
    def test_from_horizontal_to_cartesian(self):
        a, h, r = 45, 45, 7
        expected_point = geometry.Point3d(3.5, 3.5, 3.5 * math.sqrt(2))

        actual_point = converter.from_horizontal_to_cartesian(a, h, r)

        self.assertAlmostEqual(actual_point.x,
                               expected_point.x,
                               delta=self.EPS)
        self.assertAlmostEqual(actual_point.y,
                               expected_point.y,
                               delta=self.EPS)
Пример #7
0
    def build_scene(self, camera):
        view_point = Conv.from_horizontal_to_cartesian(camera.azimuth,
                                                       camera.height, 1)
        projector = Projector(
            geometry.Point3d(0, 0, 0).get_vector_to(view_point), camera.angle)

        identities_on_plate = list(
            filter(lambda identity: identity.coordinates is not None, [
                IdentifiedCoordinates(
                    star.identity,
                    projector.project_point_on_view_plate(star.coordinates))
                for star in self.identities_in_cartesian
            ]))
        identities_on_display = self.transform_to_display_coordinates(
            camera, identities_on_plate)

        identities_to_draw = list(
            filter(
                lambda p: (0 <= p.coordinates.x <= camera.display_width and 0
                           <= p.coordinates.y <= camera.display_height),
                identities_on_display))

        return identities_to_draw
Пример #8
0
 def test_point3d_get_vector_to(self):
     p = geometry.Point3d(0, 1, 3)
     v = p.get_vector_to(geometry.Point3d(2, 1, 2))
     self.assertEqual(v.x, 2)
     self.assertEqual(v.y, 0)
     self.assertEqual(v.z, -1)