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

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

问题描述

我可以找到很多关于将四元数转换为方向向量的问题,但没有其他问题,这让我觉得我做错了什么,但请耐心等待.

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.

因为在您的情况下,旋转相当无意义,只需使用向上向量作为参考(除非您的光线自上而下照射,反之亦然,否则您需要另一个参考).

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 交叉以获得新的 Un.然后使用 D、Un、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天全站免登陆