示例#1
0
 def test_plot(self):
     ""
     P0 = Point(0, 0, 0)
     N = Vector(1, 0, 0)
     pl = Plane(P0, N)
     import matplotlib.pyplot as plt
     fig = plt.figure()
     ax = fig.add_subplot(111, projection='3d')
     pl.plot(ax)
示例#2
0
    def test_point_xy(self):
        ""
        P0 = Point(0, 0, 10)
        N = Vector(0, 0, 1)
        pl = Plane(P0, N)

        self.assertEqual(pl.point_xy(1, 1), Point(1, 1, 10))

        P0 = Point(0, 0, 0)
        N = Vector(0, 1, 0)
        pl = Plane(P0, N)
        self.assertRaises(ValueError, pl.point_xy, 1, 1)
示例#3
0
    def test__intersect_line_skew(self):
        ""
        pl = Plane(P0, N)

        # perpendicular line passing through P0
        self.assertEqual(pl._intersect_line_skew(Line(P0, N)), P0)
        self.assertEqual(pl._intersect_line_skew(Line(P0 + N, N)), P0)

        # non perpendicular line not passing through P0
        self.assertEqual(
            pl._intersect_line_skew(Line(Point(0, 0, 1), Vector(1, 0, -1))),
            Point(1, 0, 0))
示例#4
0
    def test___contains__(self):
        ""
        pl = Plane(P0, N)

        # point
        self.assertTrue(pl.contains(P0))
        self.assertTrue(pl.contains(Point(10, 10, 0)))
        self.assertFalse(pl.contains(Point(0, 0, 1)))

        # line
        self.assertTrue(pl.contains(Line(P0, Vector(1, 0, 0))))
        self.assertFalse(pl.contains(Line(P0 + N, Vector(1, 0, 0))))
        self.assertFalse(pl.contains(Line(P0, N)))
示例#5
0
    def test_intersect_halfline(self):
        ""
        pl = Plane(P0, N)

        # halfline in plane
        self.assertEqual(pl.intersect_halfline(Halfline(P0, Vector(1, 0, 0))),
                         Halfline(P0, Vector(1, 0, 0)))

        # parallel halfline not in plane
        self.assertEqual(
            pl.intersect_halfline(Halfline(P0 + N, Vector(1, 0, 0))), None)

        # perpendicular halfline passing through P0
        self.assertEqual(pl.intersect_halfline(Halfline(P0, N)), P0)
        self.assertEqual(pl.intersect_halfline(Halfline(P0 + N, N.opposite)),
                         P0)

        # perpendicular line not passing through plane
        self.assertEqual(pl.intersect_halfline(Halfline(P0 + N, N)), None)
示例#6
0
    def test_intersect_line(self):
        ""
        pl = Plane(P0, N)

        # line in plane
        self.assertEqual(pl.intersect_line(Line(P0, Vector(1, 0, 0))),
                         Line(P0, Vector(1, 0, 0)))

        # parallel line not in plane
        self.assertEqual(pl.intersect_line(Line(P0 + N, Vector(1, 0, 0))),
                         None)

        # perpendicular line passing through P0
        self.assertEqual(pl.intersect_line(Line(P0, N)), P0)
        self.assertEqual(pl.intersect_line(Line(P0 + N, N)), P0)

        # non perpendicular line not passing through P0
        self.assertEqual(
            pl.intersect_line(Line(Point(0, 0, 1), Vector(1, 0, -1))),
            Point(1, 0, 0))
示例#7
0
    def test_intersect_segment(self):
        ""
        pl = Plane(P0, N)

        # segment in plane
        self.assertEqual(pl.intersect_segment(Segment(P0, Point(1, 0, 0))),
                         Segment(P0, Point(1, 0, 0)))

        # parallel segment not in plane
        self.assertEqual(
            pl.intersect_segment(Segment(P0 + N,
                                         Point(1, 0, 0) + N)), None)

        # perpendicular segment passing through P0
        self.assertEqual(pl.intersect_segment(Segment(P0, P0 + N)), P0)
        self.assertEqual(pl.intersect_segment(Segment(P0 - N, P0)), P0)

        # perpendicular segment not passing through plane
        self.assertEqual(pl.intersect_segment(Segment(P0 + N, P0 + N * 2)),
                         None)
        self.assertEqual(pl.intersect_segment(Segment(P0 - N, P0 - N * 2)),
                         None)
示例#8
0
    def test_intersection_plane(self):
        ""
        P0, N = Point(0, 0, 0), Vector(0, 0, 1)
        pl = Plane(P0, N)

        # coplanar plane
        self.assertEqual(pl.intersection(pl), GeometryObjects(pl))

        # parallel, non-coplanar planes
        self.assertEqual(pl.intersection(Plane(P0 + N, N)), GeometryObjects())

        # intersecting planes - same P0
        self.assertEqual(
            pl.intersection(Plane(P0, Vector(1, 0, 0))),
            GeometryObjects(Line(Point(0, 0, 0), Vector(0, 1, 0))))

        self.assertEqual(
            pl.intersection(Plane(P0, Vector(0, 1, 0))),
            GeometryObjects(Line(Point(0, 0, 0), Vector(-1, 0, 0))))

        self.assertEqual(
            pl.intersection(Plane(P0, Vector(1, 1, 0))),
            GeometryObjects(Line(Point(0, 0, 0), Vector(-1, 1, 0))))

        self.assertEqual(
            pl.intersection(Plane(P0, Vector(0, 1, 1))),
            GeometryObjects(Line(Point(0, 0, 0), Vector(-1, 0, 0))))

        # intersecting planes - different P0
        self.assertEqual(
            pl.intersection(Plane(P0 + Vector(1, 0, 0), Vector(1, 0, 0))),
            GeometryObjects(Line(Point(1, 0, 0), Vector(0, 1, 0))))
示例#9
0
 def test_project_3D(self):
     ""
     pl = Plane(Point(0, 0, 1), Vector(0, 0, 1))
     pt = Point(2, 2)
     self.assertEqual(pt.project_3D(pl, 2), Point(2, 2, 1.0))
示例#10
0
 def test_distance_to_point(self):
     ""
     pl = Plane(P0, N)
     self.assertEqual(pl.distance_to_point(Point(0, 0, 1)), 1)
     self.assertEqual(pl.distance_to_point(Point(0, 0, -1)), 1)
示例#11
0
 def test___repr__(self):
     ""
     pl = Plane(P0, N)
     self.assertEqual(str(pl),
                      'Plane(Point(0.0,0.0,0.0), Vector(0.0,0.0,1.0))')
示例#12
0
 def test___eq__(self):
     ""
     pl = Plane(P0, N)
     self.assertTrue(pl == pl)
     self.assertTrue(pl == Plane(P0, N.opposite))
     self.assertFalse(pl == Plane(P0, Vector(1, 0, 0)))
示例#13
0
    def test_intersect_plane(self):
        ""
        pl = Plane(P0, N)

        # coplanar plane
        self.assertEqual(pl.intersect_plane(pl), pl)

        # parallel, non-coplanar planes
        self.assertEqual(pl.intersect_plane(Plane(P0 + N, N)), None)

        # intersecting planes - same P0
        self.assertEqual(pl.intersect_plane(Plane(P0, Vector(1, 0, 0))),
                         Line(Point(0, 0, 0), Vector(0, 1, 0)))

        self.assertEqual(pl.intersect_plane(Plane(P0, Vector(0, 1, 0))),
                         Line(Point(0, 0, 0), Vector(1, 0, 0)))

        self.assertEqual(pl.intersect_plane(Plane(P0, Vector(1, 1, 0))),
                         Line(Point(0, 0, 0), Vector(-1, 1, 0)))

        self.assertEqual(pl.intersect_plane(Plane(P0, Vector(0, 1, 1))),
                         Line(Point(0, 0, 0), Vector(1, 0, 0)))

        # intersecting planes - different P0
        self.assertEqual(
            pl.intersect_plane(Plane(P0 + Vector(1, 0, 0), Vector(1, 0, 0))),
            Line(Point(1, 0, 0), Vector(0, 1, 0)))
示例#14
0
 def test___init__(self):
     ""
     pl = Plane(P0, N)
     self.assertIsInstance(pl, Plane)
     self.assertEqual(pl.P0, P0)
     self.assertEqual(pl.N, N)