Beispiel #1
0
    def test_concave_sphere(self):
        r3 = 10
        s3 = Spherical(r=-r3)

        # test for p0 ray, (0, 0, 0), (0, 0, 1)
        p0_truth = 1.0, np.array([0., 0., 0.])

        p0s3_dir = s3.intersect(self.p0, self.dir0, self.eps, self.z_dir)
        p0s3_tnp = s3.intersect_tangent_plane(self.p0, self.dir0,
                                              self.eps, self.z_dir)
        assert ((p0s3_dir[0], p0s3_dir[1].all()) ==
                (p0s3_tnp[0], p0s3_tnp[1].all()))

        p0s3 = p0s3_dir
        assert ((p0s3[0], p0s3[1].all()) == (p0_truth[0], p0_truth[1].all()))

        # test for p1 ray, (0, 1, 0), (0, 0, 1)
        sag3 = r3 - sqrt(r3*r3 - 1.0)
        p1_truth = 1-sag3, np.array([0., 1., -sag3])

        p1s3_tnp = s3.intersect_tangent_plane(self.p1, self.dir0,
                                              self.eps, self.z_dir)
        p1s3_dir = s3.intersect(self.p1, self.dir0, self.eps, self.z_dir)
        assert ((p1s3_dir[0], p1s3_dir[1].all()) ==
                (p1s3_tnp[0], p1s3_tnp[1].all()))

        p1s3 = p1s3_dir
        assert p1s3[0] == approx(p1_truth[0], rel=1e-14, abs=1e-14)
        assert p1s3[1].all() == p1_truth[1].all()

        dir_p1s3 = s3.normal(p1s3[1])
        dir_p1s3_truth = normalize(p1_truth[1] - np.array([0, 0, -r3]))
        assert dir_p1s3.all() == dir_p1s3_truth.all()
Beispiel #2
0
    def test_convex_sphere(self):
        r2 = 10
        c2 = 1/r2
        s2 = Spherical(c=c2)

        # test for p0 ray, (0, 0, 0), (0, 0, 1)
        p0_truth = 1.0, np.array([0., 0., 0.])

        p0s2_dir = s2.intersect(self.p0, self.dir0, self.eps, self.z_dir)
        p0s2_tnp = s2.intersect_tangent_plane(self.p0, self.dir0,
                                              self.eps, self.z_dir)
        assert ((p0s2_dir[0], p0s2_dir[1].all()) ==
                (p0s2_tnp[0], p0s2_tnp[1].all()))

        p0s2 = p0s2_dir
        assert ((p0s2[0], p0s2[1].all()) == (p0_truth[0], p0_truth[1].all()))

        # A spherical EvenPolynomial will use iteration to find the
        #  intersection. Use this case to further check results
        sa2 = EvenPolynomial(c=c2)
        p0sa2 = sa2.intersect(self.p0, self.dir0, self.eps, self.z_dir)
        assert ((p0sa2[0], p0sa2[1].all()) ==
                (p0_truth[0], p0_truth[1].all()))

        assert (p0s2_dir[0], p0s2_dir[1].all()) == (p0sa2[0], p0sa2[1].all())

        # test for p1 ray, (0, 1, 0), (0, 0, 1)
        sag2 = r2 - sqrt(r2*r2 - 1.0)
        p1_truth = 1+sag2, np.array([0., 1., sag2])

        p1s2_dir = s2.intersect(self.p1, self.dir0, self.eps, self.z_dir)
        p1s2_tnp = s2.intersect_tangent_plane(self.p1, self.dir0,
                                              self.eps, self.z_dir)
        assert ((p1s2_dir[0], p1s2_dir[1].all()) ==
                (p1s2_tnp[0], p1s2_tnp[1].all()))

        p1s2 = p1s2_dir
        assert ((p1s2[0], p1s2[1].all()) ==
                (p1_truth[0], p1_truth[1].all()))

        dir_p1s2 = s2.normal(p1s2[1])
        dir_p1s2_truth = -normalize(p1_truth[1] - np.array([0, 0, r2]))
        assert dir_p1s2.all() == dir_p1s2_truth.all()