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

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

问题描述

我画 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.

推荐答案

该解决方案应该是pretty的直白,而不应要求quarternions。

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

旋转轴从正常1到正常2必须都成直角的,所以才拿自己的矢量叉积

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),但因为这两个法向矢量进行归它会给余弦(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.

P.S。不要忘了, 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天全站免登陆