Example #1
0
    def test_spherical_to_extrinsic_and_inverse(self):
        dim = 2
        n_samples = 5
        sphere = Hypersphere(dim)
        points = gs.random.rand(n_samples, 2) * gs.pi * gs.array([1., 2.
                                                                  ])[None, :]
        extrinsic = sphere.spherical_to_extrinsic(points)
        result = sphere.extrinsic_to_spherical(extrinsic)
        self.assertAllClose(result, points)

        points_extrinsic = sphere.random_uniform(n_samples)
        spherical = sphere.extrinsic_to_spherical(points_extrinsic)
        result = sphere.spherical_to_extrinsic(spherical)
        self.assertAllClose(result, points_extrinsic)
Example #2
0
 def test_extrinsic_to_spherical_vectorization(self):
     dim = 2
     sphere = Hypersphere(dim)
     expected = gs.array([[gs.pi / 2, 0], [gs.pi / 6, gs.pi / 4]])
     point_extrinsic = gs.array([
         [1.0, 0.0, 0.0],
         [gs.sqrt(2.0) / 4.0,
          gs.sqrt(2.0) / 4.0,
          gs.sqrt(3.0) / 2.0],
     ])
     result = sphere.extrinsic_to_spherical(point_extrinsic)
     self.assertAllClose(result, expected)
Example #3
0
    def test_extrinsic_to_spherical(self):
        """
        Check vectorization of conversion from spherical
        to extrinsic coordinates on the 2-sphere.
        """
        dim = 2
        sphere = Hypersphere(dim)

        points_extrinsic = gs.array([1.0, 0.0, 0.0])
        result = sphere.extrinsic_to_spherical(points_extrinsic)
        expected = gs.array([gs.pi / 2, 0])
        self.assertAllClose(result, expected)
Example #4
0
    def test_tangent_spherical_and_extrinsic_inverse(self):
        dim = 2
        n_samples = 5
        sphere = Hypersphere(dim)
        points = gs.random.rand(n_samples, 2) * gs.pi * gs.array([1., 2.
                                                                  ])[None, :]
        tangent_spherical = gs.random.rand(n_samples, 2)
        tangent_extrinsic = sphere.tangent_spherical_to_extrinsic(
            tangent_spherical, points)
        result = sphere.tangent_extrinsic_to_spherical(
            tangent_extrinsic, base_point_spherical=points)
        self.assertAllClose(result, tangent_spherical)

        points_extrinsic = sphere.random_uniform(n_samples)
        vector = gs.random.rand(n_samples, dim + 1)
        tangent_extrinsic = sphere.to_tangent(vector, points_extrinsic)
        tangent_spherical = sphere.tangent_extrinsic_to_spherical(
            tangent_extrinsic, base_point=points_extrinsic)
        spherical = sphere.extrinsic_to_spherical(points_extrinsic)
        result = sphere.tangent_spherical_to_extrinsic(tangent_spherical,
                                                       spherical)
        self.assertAllClose(result, tangent_extrinsic)