Ejemplo n.º 1
0
def test_slerp():
    a = Quaternion(x, y, z, w)
    b = Quaternion(-x, -y, -z, -w)

    c = a.clone().slerp(b, 0)
    d = a.clone().slerp(b, 1)

    assert a.equals(c), "Passed"
    assert b.equals(d), "Passed"

    sqrt1_2 = sqrt(1 / 2)

    e = Quaternion(1, 0, 0, 0)
    f = Quaternion(0, 0, 1, 0)
    expected = Quaternion(sqrt1_2, 0, sqrt1_2, 0)
    result = e.clone().slerp(f, 0.5)
    assert abs(result.x - expected.x) <= eps, "Check x"
    assert abs(result.y - expected.y) <= eps, "Check y"
    assert abs(result.z - expected.z) <= eps, "Check z"
    assert abs(result.w - expected.w) <= eps, "Check w"

    g = Quaternion(0, sqrt1_2, 0, sqrt1_2)
    h = Quaternion(0, -sqrt1_2, 0, sqrt1_2)
    expected = Quaternion(0, 0, 0, 1)
    result = g.clone().slerp(h, 0.5)

    assert abs(result.x - expected.x) <= eps, "Check x"
    assert abs(result.y - expected.y) <= eps, "Check y"
    assert abs(result.z - expected.z) <= eps, "Check z"
    assert abs(result.w - expected.w) <= eps, "Check w"
Ejemplo n.º 2
0
def test_inverse_conjugate():
    a = Quaternion(x, y, z, w)

    # TODO: add better validation here.

    b = a.clone().conjugate()

    assert a.x == -b.x
    assert a.y == -b.y
    assert a.z == -b.z
    assert a.w == b.w