2017-06-22 3 views
0

Ich habe eine Quaternion Slerp mit dieser wikipedia article implementiert.So testen Sie Quaternion Slerp

Ich verstehe, wie Slerp funktioniert, mein Problem ist, dass ich Werte brauche, um meine Funktion zu testen. Kann jemand Beispiele für Quaternion Slerp geben?

Der vollständige Quellcode ist here

def slerp(quat1, quat2, t): 
    """Spherically interpolates between quat1 and quat2 by t. 
    The parameter t is clamped to the range [0, 1] 
    """ 

    # https://en.wikipedia.org/wiki/Slerp 

    v0 = normalise(quat1) 
    v1 = normalise(quat2) 

    dot = vector4.dot(v0, v1) 

    # TODO: fixlater 
    # If the inputs are too close for comfort, 
    # linearly interpolate and normalize the result. 
    # if abs(dot) > 0.9995: 
    #  pass 

    # If the dot product is negative, the quaternions 
    # have opposite handed-ness and slerp won't take 
    # the shorter path. Fix by reversing one quaternion. 
    if dot < 0.0: 
     v1 = -v1 
     dot = -dot 

    # clamp 
    dot = np.clamp(dot, -1.0, 1.0) 
    theta = np.acos(dot) * t 

    v2 = v1 - v0 * dot 
    res = v0 * np.cos(theta) + v2 * np.sin(theta) 
    return res 

Antwort

2

Mit numpy-quaternion, können Sie Ihre Ergebnisse mit der Ausgabe von quaternion.slerp_evaluate vergleichen können. Zum Beispiel:

>>> import numpy as np 
>>> import quaternion 
>>> q1 = np.quaternion(1, 0, 0, 0) 
>>> q2 = np.quaternion(0, 1, 0, 0) 
>>> quaternion.slerp_evaluate(q1, q2, .0) 
quaternion(1, 0, 0, 0) 
>>> quaternion.slerp_evaluate(q1, q2, .2) 
quaternion(0.951056516295154, 0.309016994374947, 0, 0) 
>>> quaternion.slerp_evaluate(q1, q2, .4) 
quaternion(0.809016994374947, 0.587785252292473, 0, 0) 
>>> quaternion.slerp_evaluate(q1, q2, .6) 
quaternion(0.587785252292473, 0.809016994374947, 0, 0) 
>>> quaternion.slerp_evaluate(q1, q2, .8) 
quaternion(0.309016994374947, 0.951056516295154, 0, 0) 
>>> quaternion.slerp_evaluate(q1, q2, 1.) 
quaternion(6.12323399573677e-17, 1, 0, 0) 
+0

wo ist 't0' definiert? –

+0

@SzabolcsDombi Tut mir leid, ich habe den Code korrigiert. –