Beispiel #1
0
class Plane(BaseObject):
    """A plane that contains the points: origin, p1, p2 """
    def __init__(self, color, origin, p1, p2):
        BaseObject.__init__(self)

        self.range = (-1, 1, 10)
        self.base_plane = BasePlane()
        self.base_plane.setDiffuseColor(color)
        self.base_plane.setEmissiveColor(color)
        self.separator.addChild(self.base_plane.root)
        # local axis
        self.localXAxis = Line([], color=(1, 0, 0))
        self.localYAxis = Line([], color=(1, 0, 0))
        self.separator.addChild(self.localXAxis.root)
        self.separator.addChild(self.localYAxis.root)
        # calculate the points
        self.setPoints(origin, p1, p2)

    def setPoints(self, origin, vector1, vector2):
        v1 = (vector1 - origin)
        v2 = (vector2 - origin)

        ## the plane generated by {v1, v2}
        def plane(h, t):
            return Vec3(origin) + h * v1 + t * v2

        self.base_plane.setRange(self.range, plane=plane)
        ## lines along the generators
        t_min, t_max, n = self.range
        self.localXAxis.setPoints([plane(*pt) for pt in [(t_min, 0), (t_max, 0)]])
        self.localYAxis.setPoints([plane(*pt) for pt in [(0, t_min), (0, t_max)]])
Beispiel #2
0
class Plane(BaseObject):
    """A plane that contains the points: origin, p1, p2 """
    def __init__(self, color, origin, p1, p2):
        BaseObject.__init__(self)

        self.range = (-1, 1, 10)
        self.base_plane = BasePlane()
        self.base_plane.setDiffuseColor(color)
        self.base_plane.setEmissiveColor(color)
        self.separator.addChild(self.base_plane.root)
        # local axis
        self.localXAxis = Line([], color=(1, 0, 0))
        self.localYAxis = Line([], color=(1, 0, 0))
        self.separator.addChild(self.localXAxis.root)
        self.separator.addChild(self.localYAxis.root)
        # calculate the points
        self.setPoints(origin, p1, p2)

    def setPoints(self, origin, vector1, vector2):
        v1 = (vector1 - origin)
        v2 = (vector2 - origin)

        ## the plane generated by {v1, v2}
        def plane(h, t):
            return Vec3(origin) + h * v1 + t * v2

        self.base_plane.setRange(self.range, plane=plane)
        ## lines along the generators
        t_min, t_max, n = self.range
        self.localXAxis.setPoints(
            [plane(*pt) for pt in [(t_min, 0), (t_max, 0)]])
        self.localYAxis.setPoints(
            [plane(*pt) for pt in [(0, t_min), (0, t_max)]])
Beispiel #3
0
    def test_Line(self):
        points = [p1,p2,p3,p4] = [(0,0,0),(1,1,1),(-1,2,0),(-1,-1,1)]
        line = Line([p1,p2,p3,p4])
        self.assertEqual(tuple(line[0]), p1)
        self.assertEqual(tuple(line[3]), p4)
        self.assertEqual(map(tuple,line.points), points)
        self.assertEqual(len(line), len(points))

        line.setPoints([p2,p3])
        self.assertEqual(tuple(line[0]), p2)
        self.assertEqual(tuple(line[1]), p3)
        self.assertEqual(len(line), 2)
        self.assertEqual(map(tuple,line.points), [p2,p3])
Beispiel #4
0
    def test_Line(self):
        points = [p1, p2, p3, p4] = [(0, 0, 0), (1, 1, 1), (-1, 2, 0),
                                     (-1, -1, 1)]
        line = Line([p1, p2, p3, p4])
        self.assertEqual(tuple(line[0]), p1)
        self.assertEqual(tuple(line[3]), p4)
        self.assertEqual(map(tuple, line.points), points)
        self.assertEqual(len(line), len(points))

        line.setPoints([p2, p3])
        self.assertEqual(tuple(line[0]), p2)
        self.assertEqual(tuple(line[1]), p3)
        self.assertEqual(len(line), 2)
        self.assertEqual(map(tuple, line.points), [p2, p3])