Esempio n. 1
0
    def do_antiparallel(self, th_in, th_normal, th_out_1, th_out_2):
        self.turner = self.turner_cls()
        n = 1000
        th_in = np.full([n], th_in)
        th_normal = np.full([n], th_normal)

        th_out = self.turner.get_norm_angle(th_in, th_normal, self.rng)
        print(th_out)

        frac_1 = np.isclose(angle_dist(th_out, th_out_1), 0.0).sum() / float(n)
        self.assertAlmostEqual(frac_1, 0.5, 1)
        frac_2 = np.isclose(angle_dist(th_out, th_out_2), 0.0).sum() / float(n)
        self.assertAlmostEqual(frac_2, 0.5, 1)
Esempio n. 2
0
 def do_turning(self, th_normal, th_in, th_out_expected):
     print("Normal: {:g}".format(th_normal))
     print("In: {:g}".format(th_in))
     th_in = np.array([th_in])
     th_normal = np.array([th_normal])
     th_out = self.turner.get_norm_angle(th_in, th_normal, self.rng)
     print("Out: {:g}".format(th_out[0]))
     print("Expected: {:g}".format(th_out_expected))
     self.assertTrue(np.allclose(angle_dist(th_out, th_out_expected), 0.0))
Esempio n. 3
0
 def get_angle(self, th_in, th_normal, rng, *args, **kwargs):
     if rng is None:
         rng = np.random
     th_rel = vector.normalise_angle(th_in - th_normal)
     antiparallels = np.isclose(np.abs(angle_dist(th_in, th_normal)), np.pi)
     signs = np.where(antiparallels,
                      crandom.randbool(antiparallels.shape[0], rng),
                      np.sign(th_rel))
     th_rel = signs * np.pi / 2.0
     return th_normal + th_rel
Esempio n. 4
0
 def test_equivalent_angles(self):
     th_in = self.NE
     th_in = np.array([th_in])
     th_outs = []
     for i in range(-2, 2):
         th_normal = np.pi + i * 2.0 * np.pi
         th_normal = np.array([th_normal])
         th_out = self.turner.get_norm_angle(th_in, th_normal, self.rng)
         th_outs.append(th_out[0])
     print(th_outs)
     dths = angle_dist(th_outs, th_outs[0])
     print(dths)
     self.assertTrue(np.allclose(dths, 0.0))