How to interpolate rotations?

后端 未结 4 1561
悲哀的现实
悲哀的现实 2021-02-14 15:29

I have two vectors describing rotations; a start rotation A and a target rotation B. How would I best go about interpolating A by a factor F to approach B?

Using a simpl

4条回答
  •  无人及你
    2021-02-14 16:17

    Since I don't seem to understand your question, here is a little SLERP implementation in python using numpy. I plotted the results using matplotlib (v.99 for Axes3D). I don't know if you can use python, but does look like your SLERP implementation? It seems to me to give fine results ...

    from numpy import *
    from numpy.linalg import norm
    
    def slerp(p0, p1, t):
            omega = arccos(dot(p0/norm(p0), p1/norm(p1)))
            so = sin(omega)
            return sin((1.0-t)*omega) / so * p0 + sin(t*omega)/so * p1
    
    
    # test code
    if __name__ == '__main__':
        pA = array([-2.0, 0.0, 2.0])
        pB = array([0.0, 2.0, -2.0])
    
        ps = array([slerp(pA, pB, t) for t in arange(0.0, 1.0, 0.01)])
    
        from pylab import *
        from mpl_toolkits.mplot3d import Axes3D
        f = figure()
        ax = Axes3D(f)
        ax.plot3D(ps[:,0], ps[:,1], ps[:,2], '.')
        show()
    

提交回复
热议问题