将方向向量转换为四元数旋转 [英] Converting a direction vector to a quaternion rotation

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

问题描述

关于将四元数转换为方向向量,我能找到很多问题,但反过来都没有,这让我觉得我做错了,但请忍受。

I can find a ton of questions about turning a quaternion into a direction vector but none for the other way around which makes me think I'm doing something wrong, but bear with me.

我想做的只是使用箭头模型显示定向光的方向。

What I'm trying to do is simply display the direction of a directional light using an arrow model.

定向光的方向是单位矢量但是使用四元数来旋转模型。

The directional light's direction is a unit vector but models are rotated using quaternions.

所以。如何旋转该模型以匹配光的方向?

So.. How do I rotate this model to match the direction of the light?

还是我疯了,鉴于灯光没有位置,但是模型确实有,我真的不能做到吗?

Or am I crazy and I can't really do that, given that the light has no position but the model does?

推荐答案

方向向量不是定义的旋转,它仍然具有无限数量的可能解。找不到关于如何绕轴旋转的信息。第二,矢量,矢量和旋转(具有有意义的中心)以及实际上是完全定义的矩阵都是可能的。

A direction vector is not a defined rotation, it still has an infinite number of possible solutions. See there is no information for how to rotate around the axis. Two, vectors is possible as is a vector and a rotation (with a meaningful center) and in fact a fully defined matrix.

因为在您的情况下旋转是毫无意义的,所以只需使用up向量作为参考即可(也就是说,除非您的灯光自上而下反过来,否则您需要另外一个

Because in your case the rotation is rather meaningless, just use the up vector for reference (that is unless your light is shining top down or vice-versa then you need another reference).

因此,将方向矢量D与向上矢量U的叉积作为边矢量S,然后将D和S叉积为新的U n 。然后,将D,U n ,S作为行(或列,具体取决于如何设置计算规则)作为矩阵。四元数矩阵是众所周知的数学。

So take the cross product of your direction vector D and up vector U for the side vector S then cross D and S for a new Un. Then use D, Un, S as rows (or columns depending on how your calculation rule is set up) as a matrix. Matrix to quaternion is well known math.

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

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