将 2 个 3D 点转换为方向向量到欧拉角 [英] Convert 2 3D Points to Directional Vectors to Euler Angles

查看:29
本文介绍了将 2 个 3D 点转换为方向向量到欧拉角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这基本上是我的问题.也可能我对欧拉角不够熟悉,我试图做的事情是不可能的.

Here's essentially my problem. Also maybe I am not familiar enough with Euler angles and what I'm attempting to do is not possible.

我在 3d 空间中有 2 个点.

I have 2 points in 3d space.

p1 (1,2,3)
p2 (4,5,6)

p1 (1,2,3)
p2 (4,5,6)

为了获得这两点的单位向量,我基本上是这样做的.

In order to get the unit vectors for these two points I'm doing this basically.

        var productX = (position.X2 - position.X1);
        var productY = (position.Y2 - position.Y1);
        var productZ = (position.Z2 - position.Z1);

        var normalizedTotal = Math.sqrt(productX * productX + productY * productY + productZ * productZ);

        var unitVectorX, unitVectorY, unitVectorZ;
        if(normalizedTotal == 0)
        {
            unitVectorX = productX;
            unitVectorY = productY;
            unitVectorZ = productZ;
        }
        else
        {
            unitVectorX = productX / normalizedTotal;
            unitVectorY = productY / normalizedTotal;
            unitVectorZ = productZ / normalizedTotal;
        }

所以现在我有这 2 个 3d 点的单位向量 x y z.

So now I have a unit vector x y z for these 2 3d points.

我现在正在尝试从方向向量转换为欧拉角.这可能吗.我在这里错过了什么,因为我找不到任何关于如何做到这一点的好资源.

I'm attempting now to convert from directional vector to euler angle. Is this possible. What am I missing here as I can't find any good resource on how to do this.

感谢您的帮助.

有时图片会有所帮助.

也许这会为我试图解决的问题提供一个更好的例子.

maybe this will give a better example of what i'm trying to solve for.

给定 2 点,我已经确定了一个中点、长度,现在我试图找出要设置的角度,以便圆柱体正确地围绕 x、y、z 轴定向.我想我需要弄清楚所有 3 个角度,而不仅仅是 1 和 2,对吗?我认为欧拉角从方向向量位通过你关闭.

Given 2 points, I have determined a midpoint, length, and now i'm trying to figure out hte angles to set so that the cylinder is correctly oriented around the x,y,z axis. I think I need to figure out all 3 angles not just 1 and 2 is that correct? I think the euler angles from a directional vector bit through you off.

推荐答案

你想要的是从向量的笛卡尔坐标变换

What you want is a transformation from Cartesian coordinates of the vector

v = (v_x, v_y, v_z)

到球坐标rψθ,其中

v = ( r*COS(ψ)*COS(θ), r*SIN(θ), r*SIN(ψ)*COS(θ) )

这是通过以下等式完成的

This is done with the following equations

r = SQRT(v_x^2+v_y^2+v_z^2) 
TAN(ψ) = (v_z)/(v_x)
TAN(θ) = (v_y)/(v_x^2+v_z^2)

要获得角度 ψ 和 θ,请使用 ATAN2(dy,dx) 功能如

To get the angles ψ and θ, use the ATAN2(dy,dx) function as in

ψ = ATAN2(v_z, v_x)
θ = ATAN2(v_y, SQRT(v_x^2+v_z^2))

现在你有了沿方向向量

j = ( COS(ψ)*COS(θ), SIN(θ), SIN(ψ)*COS(θ) )

你可以得到两个垂直向量

you can get the two perpendicular vectors from

i = ( SIN(ψ), 0, -COS(ψ) )
k = ( COS(ψ)*SIN(θ), -COS(θ), SIN(ψ)*SIN(θ) )

这三个向量构成了3×3旋转矩阵的列

These three vectors make up the columns of the 3×3 rotation matrix

             |  SIN(ψ)   COS(ψ)*COS(θ)    COS(ψ)*SIN(θ)  |
E =[i j k] = |    0          SIN(θ)          -COS(θ)     |
             | -COS(ψ)   SIN(ψ)*COS(θ)    SIN(ψ)*SIN(θ)  |

就欧拉角而言,上述等价于

In terms of Euler angles the above is equivalent to

E = RY(π/2-ψ)*RX(π/2-θ)

示例

两点p_1=(3,2,3)p_2=(5,6,4)定义向量

v = (5,6,4) - (3,2,3) = (2,4,1)

注意:我使用 v[i] 表示向量的 i-th 元素,如 v[1]=2 以上.这既不像基于零的 CPython,也不像 VBFORTRANMATLAB 使用括号 () 作为索引.

NOTE: I am using the notation of v[i] for the i-th element of the vector, as in v[1]=2 above. This is neither like C, Python which is zero based, nor like VB, FORTRAN or MATLAB which uses parens () for the index.

使用上面的表达式你得到

Using the expressions above you get

r = √(2^2+4^2+1^2) = √21
TAN(ψ) = 1/2 
TAN(θ) = 4/√(2^2+1^2) = 4/√5

ψ = ATAN2(1,2) = 0.463647 
θ = ATAN2(4,√5) = 1.061057

现在找到方向向量

j = ( COS(ψ)*COS(θ), SIN(θ), SIN(ψ)*COS(θ) ) = (0.4364, 0.87287, 0.21822 )
i = ( SIN(ψ), 0, -COS(ψ) ) = (0.44721, 0, -0.89443 )
k = ( COS(ψ)*SIN(θ), -COS(θ), SIN(ψ)*SIN(θ) ) = (0.78072, -0.48795, 0.39036) 

将方向向量作为局部到世界坐标变换(旋转)的列

Put the direction vectors as columns of the local to world coordinate transformation (rotation)

E[1,1] = i[1]    E[1,2] = j[1]    E[1,3] = k[1]
E[2,1] = i[2]    E[2,2] = j[2]    E[2,3] = k[2]
E[3,1] = i[3]    E[3,2] = j[3]    E[3,3] = k[3]


    |  0.447213595499957  0.436435780471984   0.780720058358826 |
    |                                                           |
E = |          0          0.872871560943969  -0.487950036474266 |
    |                                                           |
    | -0.894427190999915  0.218217890235992   0.390360029179413 |

这篇关于将 2 个 3D 点转换为方向向量到欧拉角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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