Пример #1
0
def test_inverse():
    t = Transform(Quat.from_axis_angle(Vec3(1, 1, 1), np.pi / 2), Vec3(4, 5, 6))
    t_inv = t.inverse()

    t_identity_one = t * t_inv
    t_identity_two = t_inv * t

    np_identity = np.diag((1, 1, 1, 1))
    t_fromnp = Transform.from_mat4_numpy(np_identity)

    assert np.allclose(t_identity_one.to_mat4_numpy(), np_identity)
    assert np.allclose(t_identity_two.to_mat4_numpy(), np_identity)
    assert np.allclose(t_identity_one.to_mat4_numpy(), t_identity_two.to_mat4_numpy())
    assert t_identity_one == t_fromnp
    assert t_identity_two == t_fromnp
    assert t_identity_one == t_identity_two
Пример #2
0
def test_rotation_vector():
    # Generated from - https://www.andre-gaschler.com/rotationconverter/
    # 36 degrees around axis (1, 2, 3)
    q1 = Quat(0.0825883, 0.1651765, 0.2477648, 0.9510565)
    v = q1.to_rotation_vector()

    theta = v.length()
    axis = v.normalized()

    theta_true = 36 * np.pi / 180
    axis_true = Vec3(1 / math.sqrt(14), 2 / math.sqrt(14), 3 / math.sqrt(14))

    assert abs(theta - theta_true) < MATH_EPS
    assert axis == axis_true

    rotation_vec = theta_true * axis_true
    q2 = Quat.from_rotation_vector(rotation_vec)
    assert q1 == q2

    q3 = Quat.from_axis_angle(axis_true, theta_true)
    assert q1 == q3