Beispiel #1
0
def random_point_pair():
    """
    Creates a random point pair bivector object
    """
    mv_a = random_euc_mv()
    mv_b = random_euc_mv()
    pp = (up(mv_a) ^ up(mv_b)).normal()
    return pp
Beispiel #2
0
def random_line():
    """
    Creates a random line
    """
    mv_a = random_euc_mv()
    mv_b = random_euc_mv()
    line_a = ((up(mv_a) ^ up(mv_b) ^ ninf)).normal()
    return line_a
Beispiel #3
0
def random_line():
    """
    Creates a random line
    """
    mv_a = random_euc_mv()
    mv_b = random_euc_mv()
    line_a = ((up(mv_a) ^ up(mv_b) ^ ninf)).normal()
    return line_a
Beispiel #4
0
def random_point_pair():
    """
    Creates a random point pair bivector object
    """
    mv_a = random_euc_mv()
    mv_b = random_euc_mv()
    pp = (up(mv_a) ^ up(mv_b)).normal()
    return pp
Beispiel #5
0
def random_circle():
    """
    Creates a random circle
    """
    mv_a = random_euc_mv()
    mv_b = random_euc_mv()
    mv_c = random_euc_mv()
    line_a = ((up(mv_a) ^ up(mv_b) ^ up(mv_c))).normal()
    return line_a
Beispiel #6
0
def random_bivector():
    """
    Creates a random bivector on the form described by R. Wareham in
    Mesh Vertex Pose and Position Interpolation using Geometric Algebra.
    $$ B =  ab + c*n_{\inf}$$ where $a, b, c \in \mathcal(R)^3$
    """
    a = random_euc_mv()
    c = random_euc_mv()
    return a * I3 + c * ninf
Beispiel #7
0
def random_bivector():
    """
    Creates a random bivector on the form described by R. Wareham in
    Mesh Vertex Pose and Position Interpolation using Geometric Algebra.
    $$ B =  ab + c*n_{\inf}$$ where $a, b, c \in \mathcal(R)^3$
    """
    a = random_euc_mv()
    c = random_euc_mv()
    return a * I3 + c * ninf
Beispiel #8
0
def random_bivector():
    """
    Creates a random bivector on the form described by R. Wareham in
    TODO: Dig out the name of the interpolation paper

    $$ B =  ab + c*n_{\inf}$$ where $a, b, c \in \mathcal(R)^3$
    """
    a = random_euc_mv()
    c = random_euc_mv()
    return a * I3 + c * ninf
Beispiel #9
0
def random_sphere():
    """
    Creates a random sphere
    """
    mv_a = random_euc_mv()
    mv_b = random_euc_mv()
    mv_c = random_euc_mv()
    mv_d = random_euc_mv()
    sphere = ((up(mv_a) ^ up(mv_b) ^ up(mv_c) ^ up(mv_d))).normal()
    return sphere
Beispiel #10
0
    def test_generate_translation_rotor(self):
        """ Tests translation rotor generation """

        for i in range(100):
            rand = random_euc_mv()
            starting_point = up(random_euc_mv())
            r_trans = generate_translation_rotor(rand)
            end_point = r_trans * starting_point * ~r_trans
            translation_vec = down(end_point) - down(starting_point)
            npt.assert_almost_equal(translation_vec.value, rand.value)
Beispiel #11
0
def random_sphere():
    """
    Creates a random sphere
    """
    mv_a = random_euc_mv()
    mv_b = random_euc_mv()
    mv_c = random_euc_mv()
    mv_d = random_euc_mv()
    sphere = ((up(mv_a) ^ up(mv_b) ^ up(mv_c) ^ up(mv_d))).normal()
    return sphere
Beispiel #12
0
    def test_generate_translation_rotor(self):
        """ Tests translation rotor generation """

        for i in range(100):
            rand = random_euc_mv()
            starting_point = up(random_euc_mv())
            r_trans = generate_translation_rotor(rand)
            end_point = r_trans * starting_point * ~r_trans
            translation_vec = down(end_point) - down(starting_point)
            testing.assert_almost_equal(translation_vec.value, rand.value)
Beispiel #13
0
def random_circle_at_origin():
    """
    Creates a random circle at the origin
    """
    mv_a = random_euc_mv()
    mv_r = random_euc_mv()
    r = generate_rotation_rotor(np.pi / 2, mv_a, mv_r)
    mv_b = r * mv_a * ~r
    mv_c = r * mv_b * ~r
    pp = (up(mv_a) ^ up(mv_b) ^ up(mv_c)).normal()
    return pp
Beispiel #14
0
def random_circle_at_origin():
    """
    Creates a random circle at the origin
    """
    mv_a = random_euc_mv()
    mv_r = random_euc_mv()
    r = generate_rotation_rotor(np.pi/2, mv_a, mv_r)
    mv_b = r*mv_a*~r
    mv_c = r * mv_b * ~r
    pp = (up(mv_a) ^ up(mv_b) ^ up(mv_c) ).normal()
    return pp
Beispiel #15
0
    def run_rotor_estimation(self, object_generator, estimation_function, n_runs=5, n_objects_per_run=10):

        error_count = 0
        for i in range(n_runs):
            query_model = [object_generator().normal() for i in range(n_objects_per_run)]
            r = (generate_translation_rotor(random_euc_mv(l_max=0.01)) * generate_rotation_rotor(np.random.randn() / 10,
                                                                                                 random_euc_mv().normal(),
                                                                                                 random_euc_mv().normal())).normal()

            reference_model = [(r * l * ~r).normal() for l in query_model]
            r_est = estimation_function(reference_model, query_model)
            error_flag = False
            for a, b in zip([(r_est * l * ~r_est).normal() for l in query_model], reference_model):
                if abs(a + b) < 0.0001:
                    c = -b
                    print('SIGN FLIP')
                else:
                    c = b
                if np.any(np.abs(a.value - c.value) > 0.01):
                    error_flag = True
            if error_flag:
                error_count += 1
            print(i, error_count)
        print('\n\nESTIMATION SUMMARY')
        print('OBJECTS ', n_objects_per_run)
        print('RUNS ', n_runs)
        print('ERRORS ', error_count)
        print('ERROR percentage ', 100 * error_count / float(n_runs), '%')
Beispiel #16
0
    def run_rotor_estimation(self, object_generator, estimation_function, n_runs=5, n_objects_per_run=10):

        error_count = 0
        for i in range(n_runs):
            query_model = [object_generator().normal() for i in range(n_objects_per_run)]
            r = (generate_translation_rotor(random_euc_mv(l_max=0.01)) * generate_rotation_rotor(np.random.randn() / 10,
                                                                                                 random_euc_mv().normal(),
                                                                                                 random_euc_mv().normal())).normal()

            reference_model = [(r * l * ~r).normal() for l in query_model]
            r_est = estimation_function(reference_model, query_model)
            error_flag = False
            for a, b in zip([(r_est * l * ~r_est).normal() for l in query_model], reference_model):
                if abs(a + b) < 0.0001:
                    c = -b
                    print('SIGN FLIP')
                else:
                    c = b
                if np.any(np.abs(a.value - c.value) > 0.01):
                    error_flag = True
            if error_flag:
                error_count += 1
            print(i, error_count)
        print('\n\nESTIMATION SUMMARY')
        print('OBJECTS ', n_objects_per_run)
        print('RUNS ', n_runs)
        print('ERRORS ', error_count)
        print('ERROR percentage ', 100 * error_count / float(n_runs), '%')
Beispiel #17
0
 def test_draw_points(self):
     from clifford.tools.g3 import random_euc_mv
     from clifford.g3 import layout
     gs = GanjaScene()
     gs.add_objects([random_euc_mv().value[0:8] for i in range(10)], static=False)
     with open('test_file.html', 'w') as test_file:
         print(generate_full_html(str(gs), sig=layout.sig, grid=True, scale=1.0, gl=False), file=test_file)
     render_cef_script(str(gs), sig=layout.sig, grid=True, scale=1.0, gl=False)
Beispiel #18
0
 def test_general_logarithm_translation(self):
     # Check we can reverse translation
     for i in range(50):
         t = random_euc_mv()
         biv = ninf * t / 2
         R = general_exp(biv).normal()
         biv_2 = general_logarithm(R)
         npt.assert_almost_equal(biv.value, biv_2.value)
Beispiel #19
0
 def test_general_logarithm_translation(self):
     # Check we can reverse translation
     for i in range(50):
         t = random_euc_mv()
         biv = ninf * t /2
         R = general_exp(biv).normal()
         biv_2 = general_logarithm(R)
         np.testing.assert_almost_equal(biv.value, biv_2.value)
Beispiel #20
0
 def test_from_value_array(self):
     mv = []
     for i in range(100):
         p = random_euc_mv()
         mv.append(p)
     test_array = ConformalMVArray(mv)
     up_array = test_array.up()
     new_mv_array = ConformalMVArray.from_value_array(up_array.value)
     npt.assert_almost_equal(new_mv_array.value, up_array.value)
Beispiel #21
0
 def test_from_value_array(self):
     mv = []
     for i in range(100):
         p = random_euc_mv()
         mv.append(p)
     test_array = ConformalMVArray(mv)
     up_array = test_array.up()
     new_mv_array = ConformalMVArray.from_value_array(up_array.value)
     np.testing.assert_almost_equal(new_mv_array.value, up_array.value)
Beispiel #22
0
def random_point_pair_at_origin():
    """
    Creates a random point pair bivector object at the origin
    """
    mv_a = random_euc_mv()
    plane_a = (mv_a*I3).normal()

    mv_b = plane_a*mv_a*plane_a
    pp = (up(mv_a) ^ up(mv_b)).normal()
    return pp
Beispiel #23
0
def random_point_pair_at_origin():
    """
    Creates a random point pair bivector object at the origin
    """
    mv_a = random_euc_mv()
    plane_a = (mv_a * I3).normal()

    mv_b = plane_a * mv_a * plane_a
    pp = (up(mv_a) ^ up(mv_b)).normal()
    return pp
Beispiel #24
0
    def test_dual(self):
        mv = []
        for i in range(100):
            p = random_euc_mv()
            mv.append(p)
        test_array = ConformalMVArray(mv)
        up_array = test_array.up()
        I5 = self.layout.blades['e12345']

        np.testing.assert_almost_equal((up_array * ConformalMVArray([I5])).value,
                                       ConformalMVArray([i * I5 for i in up_array]).value)
Beispiel #25
0
    def test_dual(self):
        mv = []
        for i in range(100):
            p = random_euc_mv()
            mv.append(p)
        test_array = ConformalMVArray(mv)
        up_array = test_array.up()
        I5 = self.layout.blades['e12345']

        np.testing.assert_almost_equal((up_array * ConformalMVArray([I5])).value,
                                       ConformalMVArray([i * I5 for i in up_array]).value)
Beispiel #26
0
 def test_fit_plane(self):
     noise = 0.1
     trueP = random_plane()
     point_list = project_points_to_plane(
         [random_conformal_point() for i in range(100)], trueP)
     point_list = [
         up(down(P) + noise * random_euc_mv()) for P in point_list
     ]
     print(trueP)
     plane = fit_plane(point_list)
     print(plane)
Beispiel #27
0
 def test_fit_sphere(self):
     try:
         noise = 0.1
         trueP = random_sphere()
         point_list = project_points_to_sphere([random_conformal_point() for i in range(100)], trueP)
         point_list = [up(down(P) + noise * random_euc_mv()) for P in point_list]
         print(trueP)
         sphere = fit_sphere(point_list)
         print(sphere)
         #draw([sphere] + point_list, static=False, scale=0.1)
     except:
         print('FAILED TO FIND SPHERE')
Beispiel #28
0
 def test_fit_plane(self):
     try:
         noise = 0.1
         trueP = random_plane()
         point_list = project_points_to_plane([random_conformal_point() for i in range(100)], trueP)
         point_list = [up(down(P) + noise * random_euc_mv()) for P in point_list]
         print(trueP)
         plane = fit_plane(point_list)
         print(plane)
         #draw(point_list + [plane], static=False, scale=0.1)
     except:
         print('FAILED TO FIND PLANE')
Beispiel #29
0
 def test_fit_sphere(self):
     try:
         noise = 0.1
         trueP = random_sphere()
         point_list = project_points_to_sphere([random_conformal_point() for i in range(100)], trueP)
         point_list = [up(down(P) + noise * random_euc_mv()) for P in point_list]
         print(trueP)
         sphere = fit_sphere(point_list)
         print(sphere)
         #draw([sphere] + point_list, static=False, scale=0.1)
     except:
         print('FAILED TO FIND SPHERE')
Beispiel #30
0
 def test_fit_plane(self):
     try:
         noise = 0.1
         trueP = random_plane()
         point_list = project_points_to_plane([random_conformal_point() for i in range(100)], trueP)
         point_list = [up(down(P) + noise * random_euc_mv()) for P in point_list]
         print(trueP)
         plane = fit_plane(point_list)
         print(plane)
         #draw(point_list + [plane], static=False, scale=0.1)
     except:
         print('FAILED TO FIND PLANE')
Beispiel #31
0
    def test_general_logarithm_TS(self):
        for i in range(5):
            scale = 0.5 +np.random.rand()
            t = random_euc_mv()
            S = generate_dilation_rotor(scale)
            T = generate_translation_rotor(t)
            V = ( T *S).normal()
            biv = general_logarithm(V)
            V_rebuilt = (general_exp(biv)).normal()

            C1 = random_point_pair()
            C2 = ( V *C1 *~V).normal()
            C3 = (V_rebuilt *C1 *~V_rebuilt).normal()
            np.testing.assert_almost_equal(C2.value, C3.value, 5)
Beispiel #32
0
    def test_apply_rotor(self):
        mv = []
        for i in range(100):
            p = random_euc_mv()
            mv.append(p)
        test_array = ConformalMVArray(mv)
        up_array = test_array.up()

        # Test apply rotor
        for i in range(100):
            R = ConformalMVArray([self.layout.randomRotor()])
            rotated_array = up_array.apply_rotor(R)
            for i, v in enumerate(rotated_array):
                np.testing.assert_almost_equal(v.value, apply_rotor(up_array[i], R[0]).value)
Beispiel #33
0
    def test_general_logarithm_TS(self):
        for i in range(5):
            scale = 0.5 + np.random.rand()
            t = random_euc_mv()
            S = generate_dilation_rotor(scale)
            T = generate_translation_rotor(t)
            V = (T * S).normal()
            biv = general_logarithm(V)
            V_rebuilt = (general_exp(biv)).normal()

            C1 = random_point_pair()
            C2 = (V * C1 * ~V).normal()
            C3 = (V_rebuilt * C1 * ~V_rebuilt).normal()
            npt.assert_almost_equal(C2.value, C3.value, 5)
Beispiel #34
0
    def test_apply_rotor(self):
        mv = []
        for i in range(100):
            p = random_euc_mv()
            mv.append(p)
        test_array = ConformalMVArray(mv)
        up_array = test_array.up()

        # Test apply rotor
        for i in range(100):
            R = ConformalMVArray([self.layout.randomRotor()])
            rotated_array = up_array.apply_rotor(R)
            for i, v in enumerate(rotated_array):
                np.testing.assert_almost_equal(v.value, apply_rotor(up_array[i], R[0]).value)
Beispiel #35
0
 def test_up_down(self):
     mv = []
     up_mv = []
     for i in range(100):
         p = random_euc_mv()
         mv.append(p)
         up_mv.append(up(p))
     test_array = ConformalMVArray(mv)
     up_array = test_array.up()
     down_array = up_array.down()
     for a, b in zip(up_array, up_mv):
         np.testing.assert_almost_equal(a.value, b.value)
         np.testing.assert_almost_equal(a.value, b.value)
     for a, b in zip(down_array, mv):
         np.testing.assert_almost_equal(a.value, b.value)
Beispiel #36
0
 def test_up_down(self):
     mv = []
     up_mv = []
     for i in range(100):
         p = random_euc_mv()
         mv.append(p)
         up_mv.append(up(p))
     test_array = ConformalMVArray(mv)
     up_array = test_array.up()
     down_array = up_array.down()
     for a, b in zip(up_array, up_mv):
         npt.assert_almost_equal(a.value, b.value)
         npt.assert_almost_equal(a.value, b.value)
     for a, b in zip(down_array, mv):
         npt.assert_almost_equal(a.value, b.value)
Beispiel #37
0
 def test_find_rotor_aligning_vectors(self, rng):  # noqa: F811
     """
     Currently fails, needs to be dug into
     """
     from clifford.g3c import layout
     e1 = layout.blades['e1']
     e2 = layout.blades['e2']
     from clifford.tools.g3 import random_euc_mv, random_rotation_rotor, rotor_align_vecs
     u_list = [random_euc_mv(rng=rng) for i in range(50)]
     for i in range(100):
         r = random_rotation_rotor(rng=rng)
         v_list = [r * u * ~r for u in u_list]
         r_2 = rotor_align_vecs(u_list, v_list)
         print(r_2)
         print(r)
         testing.assert_almost_equal(r.value, r_2.value)
Beispiel #38
0
 def test_find_rotor_aligning_vectors(self):
     """
     Currently fails, needs to be dug into
     """
     from clifford.g3c import layout
     e1 = layout.blades['e1']
     e2 = layout.blades['e2']
     from clifford.tools.g3 import random_euc_mv, random_rotation_rotor, rotor_align_vecs
     u_list = [random_euc_mv() for i in range(50)]
     for i in range(100):
         r = random_rotation_rotor()
         v_list = [r*u*~r for u in u_list]
         r_2 = rotor_align_vecs(u_list, v_list)
         print(r_2)
         print(r)
         testing.assert_almost_equal(r.value, r_2.value)
Beispiel #39
0
    def test_get_properties_of_sphere(self):
        for i in range(100):
            # Make a sphere
            scale_factor = np.random.rand()
            sphere = (up(scale_factor * e1) ^ up(-scale_factor * e1)
                      ^ up(scale_factor * e3)
                      ^ up(scale_factor * e2)).normal()
            # Translate it
            rand_trans = random_euc_mv()
            trans_rot = generate_translation_rotor(rand_trans)
            sphere = (trans_rot * sphere * ~trans_rot).normal()

            center = get_center_from_sphere(sphere)
            radius = get_radius_from_sphere(sphere)

            npt.assert_almost_equal(down(center).value, rand_trans.value)
            npt.assert_almost_equal(radius, scale_factor)
Beispiel #40
0
    def test_get_properties_of_sphere(self):

        for i in range(100):
            # Make a sphere
            scale_factor = np.random.rand()
            sphere = (up(scale_factor * e1) ^ up(-scale_factor * e1) ^ up(scale_factor * e3) ^ up(
                scale_factor * e2)).normal()
            # Translate it
            rand_trans = random_euc_mv()
            trans_rot = generate_translation_rotor(rand_trans)
            sphere = (trans_rot * sphere * ~trans_rot).normal()

            center = get_center_from_sphere(sphere)
            radius = get_radius_from_sphere(sphere)

            testing.assert_almost_equal(down(center).value, rand_trans.value)
            testing.assert_almost_equal(radius, scale_factor)
Beispiel #41
0
def random_translation_rotor(maximum_translation=10.0):
    """ generate a random translation rotor """
    return generate_translation_rotor(random_euc_mv(maximum_translation))
Beispiel #42
0
 def test_generate_translation_rotor(self):
     for i in range(10000):
         euc_vector_a = random_euc_mv()
         res = generate_translation_rotor(euc_vector_a)
         res2 = (1 + ninf * euc_vector_a / 2)
         npt.assert_almost_equal(res.value, res2.value)
Beispiel #43
0
def random_conformal_point(l_max=10):
    """
    Creates a random conformal point
    """
    return up(random_euc_mv(l_max=l_max))
Beispiel #44
0
def random_translation_rotor(maximum_translation=10.0):
    """ generate a random translation rotor """
    return generate_translation_rotor(random_euc_mv(maximum_translation))
Beispiel #45
0
def random_conformal_point(l_max=10):
    """
    Creates a random conformal point
    """
    return up(random_euc_mv(l_max=l_max))