本文介绍了如何在 3D 中计算一个点的偏航、俯仰和滚转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

给定 3D 空间中的一个点,将一条线变换为指向该对象所需的三个角度(例如欧拉角)是多少?

假设我有一条 3D 线(或一个框),我想将其航向、俯仰角和坡度转换为从原点指向 3D 点,我将使用哪些值来表示这些角度?

我无法计算出指向某个位置的角度的数学方法,例如 (1,2,3).

解决方案

注意:我将使用

1.求震级

首先,让我们找到最简单的值,即幅度.对我们来说幸运的是,无论我们在多少维中,任何两点之间的大小(长度)都很容易找到,只需使用 勾股定理.由于我们在 3D 环境中,并且我们正在计算从原点到我们点的距离,因此我们的距离公式变为:

magnitude = sqrt(x*x + y*y + z*z)

插入我们的实际值:

magnitude = sqrt(1*1 + 2*2 + 3*3)= 3.7416573868

所以我们的幅度(或长度)是 ~3.741.

2.找到标题

接下来,要找到航向,请注意我们只关心关于 XZ 平面的旋转,我们根本不关心 Y 轴.如果我们要将 3D 空间展平"为 2D,找到标题就变得微不足道.

我们可以绘制一个与 X 轴(红色三角形)形成 90 度角的三角形,然后计算该角度.回忆三角学tan(angle) =对/相邻,求解angle,我们得到angle = arctan(opposite/neighbor).

在这种情况下,相邻"是一个已知量(redAdjacent = x = 1),相反"也是已知的(redOpposite = z = 3).不过,我们想使用 atan2 而不是使用 arctan 来求解方程,因为它会处理所有对我们来说 x 和 y 的不同情况.

所以我们有:

heading = atan2(redOpposite, redAdjacent)

插入我们的实际值:

heading = atan2(3, 1)= 1.249045772398

所以我们的航向1.249弧度,或~72°.

3.找到音高

最后我们需要找到音高.与我们对航向所做的类似,我们可以沿着包含以下三个点的平面将 3D 空间展平为 2D:(A) 原点 (0,0,0), (B)我们的点 (1,2,3),和 (C) 我们的点,因为它会投影到 XZ 平面 (1,0,3)(例如通过设置 0为 Y 值).

如果我们在这 3 个点之间画一个三角形,您会注意到它们又形成了一个直角三角形(绿色三角形).我们可以再次使用 arctan2 简单地计算角度.

我们已经在步骤 1 中计算了绿色斜边(即向量的大小):

greenHypotenuse = sqrt(x*x + y*y + z*z)= 3.7416573868

我们也知道绿色三角形的反面与y值相同:

greenOpposite = y= 2

利用勾股定理,我们可以求出相邻角的长度:

greenOpposite^2 + greenAdjacent^2 = greenHypotenuse^2y*y + greenAdjacent^2 = x*x + y*y + z*zgreenAdjacent^2 = x*x + z*z绿色相邻 = sqrt(x*x + z*z)

注意另一种计算绿色三角形相邻长度的方法是注意redHypotenuse == greenAdjacent,我们可以使用:

找到redHypotenuse

redHypotenuse^2 = redAdjacent^2 + redOpposite^2= x*x + z*zredHypotenuse = sqrt(x*x + z*z)

插入实际值,我们得到:

greenAdjacent = sqrt(1*1 + 3*3)= 3.1622776602

既然我们知道了绿色三角形的相邻长度和相对长度,我们可以再次使用arctan2:

pitch = atan2(greenOpposite, greenAdjacent)= atan2(2, 3.1622776602)= 0.563942641356

所以我们的螺距0.5634弧度,或大约32°.

结论

如果你从原点画一条线,长度为3.741,航向1.249 rad,间距0.564 rad,它会从 (0,0,0) 扩展到 (1,2,3).

Given a point in 3D space, what are the three angles (e.g. Euler angles) needed to transform a line to point to that object?

Imagine I have a line (or a box) in 3D and I want to transform its heading, pitch, and bank to point to the 3D point from the origin, what values would I use for those angles?

I can't figure out the math to calculate the angles to point to a location such as (1,2,3).

解决方案

Note: Instead of "yaw, pitch, roll", I'm going to use the conventions "heading, pitch, bank" as defined by 3D Math Primer for Graphics and Game Development by Fletcher Dunn.

Firstly, notice that in a 2D coordinate system, you only need a single angle + magnitude to "point" to any point in 2D.

Similarly, in a 3D coordinate system, you only need two angles + magnitude to "point" to any point in 3D. The last angle ("bank" or "roll") does not affect the location of a point in 3D. Instead it "spins" the arrow that would point to it. If the object is 360 degrees symmetrical, you won't see spin affecting the object at all. If the object is not symmetrical (e.g. an airplane) it will affect the object (e.g. tilting one wing towards the ground and the other towards the sky).

So the original question actually becomes, "how do I find the heading angle, pitch angle, and magnitude to "point" to any point in 3D space?"

You can easily figure this out using trigonometry functions. Imagine we have the point (1,2,3) and we're trying to calculate the heading, pitch, magnitude.

For the following example, let's use this diagram, where the left axis is X, up is Y, and right is Z. The point (1,2,3), then is represented by the blue sphere.

1. Find the magnitude

First, let's find the easiest value, the magnitude. Luckily for us, the magnitude (length) between any two points is easy to find no matter how many dimensions we are in, simply by using the Pythagorean theorem. Since we are in 3D and we're calculating the distance from the origin to our point, our distance formula becomes:

magnitude = sqrt(x*x + y*y + z*z)

Plugging in our actual values:

magnitude = sqrt(1*1 + 2*2 + 3*3)
          = 3.7416573868

So our magnitude (or length) is ~3.741.

2. Find the heading

Next, to find the heading, notice that we just care about rotation about the XZ plane, and we don't care about the Y-axis at all. If we were to "flatten" the 3D space into 2D, it becomes trivial to find the heading.

We can draw a triangle that forms a 90 degree angle with the X-axis (red triangle) and then calculate that angle. Recall from trigonometry tan(angle) = opposite / adjacent, and solving for angle, we get angle = arctan(opposite / adjacent).

In this case "adjacent" is a known quantity (redAdjacent = x = 1), and "opposite" is known too (redOpposite = z = 3). Instead of using arctan to solve the equation though, we want to use atan2 since it'll handle all the different cases of x and y for us.

So we have:

heading = atan2(redOpposite, redAdjacent)

Plugging in our actual values:

heading = atan2(3, 1)
        = 1.249045772398

so our heading is 1.249 rad, or ~72°.

3. Find the pitch

Finally we need to find the pitch. Similarly to what we did with the heading, we can flatten the the 3D space into 2D along the plane that contains these three points: (A) the origin (0,0,0), (B) our point (1,2,3), and (C) our point as it would project onto the XZ plane (1,0,3) (e.g. by setting 0 for the Y-value).

If we draw a triangle between all 3 of these points, you will notice that they form a right-triangle again (green triangle). We can simply calculate the angle using arctan2 again.

We already calculated the green hypotenuse in step 1 (i.e. the magnitude of our vector):

greenHypotenuse = sqrt(x*x + y*y + z*z)
                = 3.7416573868

We also know the opposite of the green triangle is the same as the y-value:

greenOpposite = y
              = 2

Using the pythagorean theorem, we can find the length of the adjacent angle:

greenOpposite^2 + greenAdjacent^2 = greenHypotenuse^2
y*y + greenAdjacent^2 = x*x + y*y + z*z
greenAdjacent^2 = x*x + z*z
greenAdjacent = sqrt(x*x + z*z)

Notice that another way to calculate the adjacent length of the green triangle is to notice that redHypotenuse == greenAdjacent, and we could find redHypotenuse using:

redHypotenuse^2 = redAdjacent^2 + redOpposite^2
                = x*x + z*z
redHypotenuse = sqrt(x*x + z*z)

Plugging in actual values, we get:

greenAdjacent = sqrt(1*1 + 3*3)
              = 3.1622776602

So now that we know the adjacent and opposite lengths of the green triangle, we can use arctan2 again:

pitch = atan2(greenOpposite, greenAdjacent)
      = atan2(2, 3.1622776602)
      = 0.563942641356

So our pitch is 0.5634 radians, or about 32°.

Conclusion

If you were to draw a line from the origin, with length 3.741, heading 1.249 rad, and pitch 0.564 rad, it would extend from (0,0,0) to (1,2,3).

这篇关于如何在 3D 中计算一个点的偏航、俯仰和滚转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:13