Esempio n. 1
0
    def test_tangent(self):
        q = QuadricCollection([Sphere(), Sphere(radius=2)])
        p = PointCollection([Point(1, 0, 0), Point(2, 0, 0)])

        assert all(q.contains(p))
        assert q.tangent(at=p) == PlaneCollection([Plane(1, 0, 0, -1), Plane(1, 0, 0, -2)])
        assert all(q.is_tangent(q.tangent(at=p)))
Esempio n. 2
0
    def test_intersect(self):
        q = QuadricCollection([Circle(Point(0, 1), 1), Circle(Point(0, 2), 2)])
        l = LineCollection(
            [Line(Point(-1, 1), Point(1, 1)),
             Line(Point(-1, 2), Point(1, 2))])

        assert q.intersect(l) == [
            PointCollection([Point(1, 1), Point(-2, 2)]),
            PointCollection([Point(-1, 1), Point(2, 2)]),
        ]

        q = QuadricCollection(
            [Sphere(Point(0, 0, 1), 1),
             Sphere(Point(0, 0, 2), 2)])
        l = LineCollection([
            Line(Point(-1, 0, 1), Point(1, 0, 1)),
            Line(Point(-1, 0, 2), Point(1, 0, 2)),
        ])
        m = Line(Point(-1, 0, 2), Point(1, 0, 2))

        assert q.intersect(l) == [
            PointCollection([Point(-1, 0, 1), Point(-2, 0, 2)]),
            PointCollection([Point(1, 0, 1), Point(2, 0, 2)]),
        ]
        assert q.intersect(m) == [
            PointCollection([Point(0, 0, 2), Point(-2, 0, 2)]),
            PointCollection([Point(0, 0, 2), Point(2, 0, 2)]),
        ]
Esempio n. 3
0
    def test_s3(self):
        s3 = Sphere(Point(1, 2, 3, 4), 5)

        assert s3.center == Point(1, 2, 3, 4)
        assert np.isclose(s3.radius, 5)
        assert np.isclose(s3.volume, 1 / 2 * np.pi**2 * 5**4)
        assert np.isclose(s3.area, 2 * np.pi**2 * 5**3)
Esempio n. 4
0
    def test_s2(self):
        s2 = Sphere()

        assert s2.center == Point(0, 0, 0)
        assert np.isclose(s2.radius, 1)
        assert np.isclose(s2.volume, 4 / 3 * np.pi)
        assert np.isclose(s2.area, 4 * np.pi)
    def test_intersection(self):
        s = Sphere(Point(0, 0, 2), 2)
        l = Line(Point(-1, 0, 2), Point(1, 0, 2))

        assert s.contains(Point(0, 0, 0))
        assert s.intersect(l) == [Point(-2, 0, 2), Point(2, 0, 2)]
        assert s.intersect(l-Point(0, 0, 2)) == [Point(0, 0, 0)]

        s = Sphere(Point(0, 0, 0, 2), 2)
        l = Line(Point(-1, 0, 0, 2), Point(1, 0, 0, 2))

        assert s.contains(Point(0, 0, 0, 0))
        assert s.intersect(l) == [Point(2, 0, 0, 2), Point(-2, 0, 0, 2)]
Esempio n. 6
0
    def test_intersect(self):
        s = Sphere(Point(0, 0, 2), 2)
        l = Line(Point(-1, 0, 2), Point(1, 0, 2))

        assert s.contains(Point(0, 0, 0))
        assert s.intersect(l) == [Point(-2, 0, 2), Point(2, 0, 2)]
        assert s.intersect(l - Point(0, 0, 2)) == [Point(0, 0, 0)]

        l = LineCollection([Line(Point(-1, 0, 2), Point(1, 0, 2)), Line(Point(0, 0, 0), Point(0, 0, 2))])
        assert s.intersect(l) == [PointCollection([Point(-2, 0, 2), Point(0, 0, 0)]),
                                  PointCollection([Point(2, 0, 2), Point(0, 0, 4)])]

        s = Sphere(Point(0, 0, 0, 2), 2)
        l = Line(Point(-1, 0, 0, 2), Point(1, 0, 0, 2))

        assert s.contains(Point(0, 0, 0, 0))
        assert s.intersect(l) == [Point(2, 0, 0, 2), Point(-2, 0, 0, 2)]
Esempio n. 7
0
    def test_contains(self):
        s = QuadricCollection([Sphere(), Sphere(radius=2)])
        p = Point(1, 0, 0)

        assert np.all(s.contains(p) == [True, False])
Esempio n. 8
0
    def test_add(self):
        s = Sphere()
        p = Point(0, 0, 2)

        assert s + p == Sphere(p)
        assert s - p == Sphere(-p)
Esempio n. 9
0
    def test_transform(self):
        s = Sphere(Point(0, 0, 2), 2)
        t = translation(1, 1, -1)

        assert t * s == Sphere(Point(1, 1, 1), 2)