Ejemplo n.º 1
0
def test_rotation_matrix():
    sample_count = 10
    vec_len_range = 10000
    theta_range = pi  # if > pi, may cause test fail, but don't worry.
    tol = 1e-4
    for i in xrange(sample_count):
        axis_dir = random_vec(vec_len_range)
        vec_to_rotate = random_vec(vec_len_range)
        theta = random_float(theta_range)
        mat = rotation_array(theta, axis_dir)
        rotated_vec = mat.dot(vec_to_rotate)
        rotated_vec2 = mat.dot(rotated_vec)

        act_theta = intersec_angle(projection_to_plan(vec_to_rotate,
                                   axis_dir),
                                   projection_to_plan(rotated_vec,
                                   axis_dir))
        act_theta *= cmp(np.dot(np.cross(vec_to_rotate, rotated_vec),
                         axis_dir), 0)

        feqok_(act_theta, theta, tol)
        if theta < pi * tol:
            continue
        feqok_(vec_len(vec_to_rotate), vec_len(rotated_vec), tol)
        (r, center) = circum(vec_to_rotate, rotated_vec, rotated_vec2)
        feqok_(vec_len(np.cross(center, axis_dir)), 0, tol
               * max(vec_len(axis_dir), vec_len(center)))
        ok_(cmp(np.dot(center, axis_dir), 0)
            == cmp(np.dot(vec_to_rotate, axis_dir), 0))
Ejemplo n.º 2
0
def test_circum():
    vec_len_range = 10000
    sample_count = 1000
    tol = 1e-6
    for i in xrange(sample_count):
        p1 = random_vec(vec_len_range)
        p2 = random_vec(vec_len_range)
        p3 = random_vec(vec_len_range)
        (r, center) = circum(p1, p2, p3)
        err = max(vec_len(p1 - p2), vec_len(p2 - p3), vec_len(p3 - p1)) \
            * tol
        feqok_(vec_len(p1 - center), r, err)
        feqok_(vec_len(p2 - center), r, err)
        feqok_(vec_len(p3 - center), r, err)
        feqok_((p1 - center).dot(np.cross(p2 - center, p3 - center)),
               0, tol * vec_len(np.cross(p2 - center, p3 - center))
               * vec_len(p1 - center))