示例#1
0
    def test_transform(self):
        c = Cylinder(center=Point(1, 0, 0), direction=Point(1, 0, 0), radius=4)
        t = translation(1, 1, 1)
        r = rotation(np.pi / 2, axis=Point(0, 1, 0))

        assert t * c == Cylinder(center=Point(2, 1, 1), direction=Point(1, 0, 0), radius=4)
        assert r * c == Cylinder(center=Point(0, 0, 1), direction=Point(0, 0, 1), radius=4)
示例#2
0
    def test_init(self):
        c = Cylinder(center=Point(1, 0, 0), direction=Point(1, 0, 0), radius=4)

        assert c.contains(Point(1, 0, 4))
        assert c.contains(Point(2, 4, 0))
        assert c.contains(Point(2, 0, 4))
        assert c.contains(Point(-1, 0, -4))

        c = Cylinder(direction=Point(1, 1, 1), radius=2)

        s = np.sqrt(2)
        assert c.contains(Point(2 + s, 2 - s, 2))
        assert c.contains(Point(2, 2 - s, 2 + s))
        assert c.contains(Point(s, 0, -s))
        assert c.contains(Point(42 + s, 42, 42 - s))
示例#3
0
    def test_intersect(self):
        c = Cylinder()
        l = Line(Point(-2, -2, 2), Point(2, 2, 2))

        s = np.sqrt(2) / 2
        assert c.intersect(l) == [Point(s, s, 2), Point(-s, -s, 2)]