确定偏航,俯仰和滚转 [英] Determining yaw, pitch and roll

查看:393
本文介绍了确定偏航,俯仰和滚转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如果从屏幕上看,x轴朝右,y轴在屏幕前方,z轴是向上。



我有一个点(x1,y1,z1),它正在寻找目标点(x2,y2,z2)。我想以度数计算偏航,俯仰和滚动。



我尝试计算旋转矩阵和角度,但似乎它没有给出正确的结果。 />


任何人都可以帮帮我。



提前致谢。



-swapna

Hi All,

If I look from my screen, x-axis is towards right, y-axis is in-front of screen and z-axis is upwards.

I have a point(x1, y1, z1) and it is looking at target point(x2, y2, z2). I would like to calculate yaw, pitch and roll in degrees.

I tried calculating rotational matrix and angles but it seems that it is not giving a right result.

Can anyone please help me out.

Thanks in advance.

-swapna

推荐答案

首先,您的y轴应指向屏幕,否则您将没有右手坐标系,这可能会在调整给定算法(如解决方案1中链接的算法)时弄乱您的公式。



其次,您的信息不足以确定滚动角度:它可以是任何值。



第三,伪码的算法看起来像这样:

从一点移动到另一个给你一个方向。它由向量 V 定义,你可以减去两点。

First, your y axis should point towards the screen, or else you won't have a right-handed coordinate system, and that might mess up your formulas when adapting a given algorithm such as the one linked to in Solution 1.

Second, your information does not suffice to determine the roll angle: it could be any value.

Third, the algorithm, in pseudocode, looks something like this:
Moving from one point to another gives you a direction. it is definied by the vector V you get by subtracting the two points.
V := (v1, v2, v3) = (x2, y2, z2) - (x1, y1, z1) = (x2-x1, y2- y1, z2- z1)



偏航角是该矢量与该水平面相同矢量的投影VP所包围的角度。只需将z坐标设置为0即可获得该向量。


The yaw angle is the angle this vector encloses with the projection VP of that same vector with the horizontal plane. You can get that vector simply by setting the z-coordinate to 0.

VP := (v1, v2, 0)



要计算偏航角,请利用两个矢量的标量乘积等于其各自长度与封闭角的余弦的乘积这一事实: V * VP = | V | * | VP | * cos(偏航)。基于此,你得到:


To calculate the yaw angle, take advantage of the fact that the scalar product of two vectors equates the product of their respective lengths and the cosine of the enclosed angle, in this case: V*VP = |V|*|VP|*cos(yaw). Based on this, you get:

yaw := acos ( V*VP/(|V|*|VP|) )



Pitch是VP与yz平面包围的角度。您可以通过首先将 VP 投影到yz平面中来获得它...


Pitch is the angle that VP encloses with the y-z plane. You can get it in the very same manner, by first projecting VP into the y-z plane ...

VPP := (0, v2, 0)



...然后计算 VPP 之间的角度和 VP


... and then calculate the angle enclosed between VPP and VP:

pitch = acos( VP*VPP / (|VP|*|VPP|) )





剩下要做的就是把它放到C / C ++代码中,并实现计算标量乘积的函数 v1 * v2 两个向量 v1 v2 ,长度<$给定向量的c $ c> | v | v



What is left to do for you is put this into C/C++ code, and implement functions for calculating the scalar product v1*v2 of two vectors v1 and v2, and the length |v| of a given vector v.


你见过这个帖子,它似乎给你所需的所有计算;

http://forum.onlineconversion。 com / showthread.php?t = 5408 [ ^ ]
Have you seen this thread, it appears to give you all the calcs required;
http://forum.onlineconversion.com/showthread.php?t=5408[^]


如果有人在寻找佛ra 简单的代码解决方案,只需从源和目标(lookat)创建一个矩阵,并使用以下代码(C#):



If anyone is looking for a simple code solution, just create a matrix from source and target (lookat), and use the following code (C#):

public void ExtractYawPitchRoll( out float yaw, out float pitch, out float roll )
{
    yaw   = (float) Math.Atan2( V02, V22 );
    pitch = (float) Math.Asin( -V12 );
    roll  = (float) Math.Atan2( V10, V11 );
}





我知道这个问题适用于C ++,但它应该很容易转换。例如,如果将C#与MonoGame一起使用,则完整代码如下所示:





I know the question is for C++ but it should be fairly easy to convert. If using C# with MonoGame, for example, the full code looks like this:

Matrix matrix = Matrix.CreateLookAt(source, target, Vector3.Up);
float yaw = (float)Math.Atan2(matrix.M13, matrix.M33);
float pitch = (float)Math.Asin(-matrix.M23);
float roll = (float)Math.Atan2(matrix.M21, matrix.M22);





原始代码:



aforge /主机上的Matrix4x4.cs·cureos / aforge·GitHub [ ^ ]


这篇关于确定偏航,俯仰和滚转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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