旋转的四元数数学? [英] Quaternion math for rotation?

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

问题描述

我正在我的场景中使用 gluDisk() 绘制一个平面磁盘.gluDisk() 绘制面向正 Z 轴的磁盘,但我希望它面向我拥有的任意法线.
显然我需要使用 glRotate() 来使磁盘正确面对,但旋转应该是什么?我记得这可以使用四元数计算,但我似乎不记得数学了.

I'm drawing a flat disk using gluDisk() in my scene. gluDisk() draws the disk facing the positive Z axis but I want it to be facing some arbitrary normal I have.
Clearly I need to use glRotate() to get the disk facing properly but what should be the rotation? I remember this can be calculated using Quaternions but I can't seem to remember the math.

推荐答案

解决方案应该非常简单,并且不应该需要四分之一.

The solution should be pretty straightforward, and shouldn't require quarternions.

从 Normal1 到 Normal2 的旋转轴必须与两者正交,因此只需取它们的向量叉积.

The axis of rotation to get from Normal1 to Normal2 must be orthogonal to both, so just take their vector cross-product.

旋转量很容易从它们的点积推导出来.这个值是|A|.|B|.cos(theta),但是由于两个法向量要归一化,所以会得到cos(theta),所以只要取反余弦就可以得到旋转量.

The amount of rotation is easily derived from their dot-product. This value is |A|.|B|.cos(theta), but as the two normal vectors should be normalised it will give cos(theta), so just take the inverse cosine to get the rotation amount.

结果向量和角度是 glRotate() 所需的参数 - 无需自己计算实际的旋转矩阵.

The resulting vector and angle are the required parameters for glRotate() - there's no need to calculate the actual rotation matrix yourself.

附言不要忘记 glRotate() 需要以度为单位的角度,但普通的 C 三角函数以弧度为单位工作.

p.s. don't forget that glRotate() needs the angle in degrees, but the normal C trig functions work in radians.

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

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