如何插入旋转? [英] How to interpolate rotations?

查看:14
本文介绍了如何插入旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个描述旋转的向量;开始旋转 A 和目标旋转 B.我如何最好地通过因子 F 插入 A 以接近 B?

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?

当需要对多个维度进行插值(即产生不需要的旋转)时,在向量上使用简单的 lerp 不起作用.也许从旋转向量构建四元数并使用 slerp 是可行的方法.但是,那么,我怎样才能从结果四元数中提取一个描述新旋转的向量呢?

Using a simple lerp on the vectors fails to work when more than one dimension needs to be interpolated (i.e. produces undesirable rotations). Maybe building quaternions from the rotation vectors and using slerp is the way to go. But how, then, could I extract a vector describing the new rotation from the resulting quaternion?

提前致谢.

推荐答案

由于我似乎不明白你的问题,这里有一点 SLERP 使用 numpy 在 python 中实现.我使用 matplotlib(Axes3D 的 v.99)绘制了结果.我不知道你是否可以使用 python,但看起来像你的 SLERP 实现吗?在我看来,结果很好......

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()

这篇关于如何插入旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆