Beispiel #1
0
    def test_line_to_ray(self):
        p0 = (0.0, 0.0)
        p1 = (1.0, 1.0)
        p2 = (1.0, 0.0)

        ray = GeometryTools.lineToRay(p0, p1)
        self.assertEqual(ray, (1.0 / sqrt(2.0), 1.0 / sqrt(2.0)))

        ray = GeometryTools.lineToRay(p1, p0)
        self.assertEqual(ray, (-1.0 / sqrt(2.0), -1.0 / sqrt(2.0)))

        ray = GeometryTools.lineToRay(p0, p2)
        self.assertEqual(ray, (1.0, 0.0))
Beispiel #2
0
    def test_line_to_ray(self):
        p0 = (0.0, 0.0)
        p1 = (1.0, 1.0)
        p2 = (1.0, 0.0)

        ray = GeometryTools.lineToRay(p0, p1)
        self.assertEqual(ray, (1.0 / sqrt(2.0), 1.0 / sqrt(2.0)))

        ray = GeometryTools.lineToRay(p1, p0)
        self.assertEqual(ray, (-1.0 / sqrt(2.0), -1.0 / sqrt(2.0)))

        ray = GeometryTools.lineToRay(p0, p2)
        self.assertEqual(ray, (1.0, 0.0))
Beispiel #3
0
    def test_ray_line_intersection(self):
        p0 = (0.0, 0.0)
        p1 = (0.0, 1.0)
        p2 = (1.0, 1.0)
        p3 = (1.0, 0.0)
        p5 = (2.0, 1.0)

        ray1 = GeometryTools.lineToRay(p0, p2)
        ray2 = GeometryTools.lineToRay(p2, p0)
        ray3 = GeometryTools.lineToRay(p0, p5)

        self.assertEqual((0.5, 0.5), GeometryTools.rayLineIntersection(p0, ray1, p1, p3))
        self.assertIsNone(GeometryTools.rayLineIntersection(p0, ray2, p1, p3)) #ray2 is ray1 reversed (no backwards intersections)

        self.assertEqual((1.0, 0.5), GeometryTools.rayLineIntersection(p0, ray3, p2, p3))
        self.assertIsNone(GeometryTools.rayLineIntersection(p0, ray3, p1, p2))
Beispiel #4
0
    def test_ray_line_intersection(self):
        p0 = (0.0, 0.0)
        p1 = (0.0, 1.0)
        p2 = (1.0, 1.0)
        p3 = (1.0, 0.0)
        p5 = (2.0, 1.0)

        ray1 = GeometryTools.lineToRay(p0, p2)
        ray2 = GeometryTools.lineToRay(p2, p0)
        ray3 = GeometryTools.lineToRay(p0, p5)

        self.assertEqual((0.5, 0.5),
                         GeometryTools.rayLineIntersection(p0, ray1, p1, p3))
        self.assertIsNone(GeometryTools.rayLineIntersection(
            p0, ray2, p1,
            p3))  #ray2 is ray1 reversed (no backwards intersections)

        self.assertEqual((1.0, 0.5),
                         GeometryTools.rayLineIntersection(p0, ray3, p2, p3))
        self.assertIsNone(GeometryTools.rayLineIntersection(p0, ray3, p1, p2))