简体   繁体   English

从球体上的 3d 点计算 RPY(滚动俯仰偏航)

[英]Compute a RPY (roll pitch yaw) from a 3d point on a sphere

I need a method to find a set of homogenous transformation matrices that describes the position and orientation in a sphere.我需要一种方法来找到一组描述球体中位置和方向的齐次变换矩阵。

The idea is that I have an object in the center of this sphere which has a radius of dz.这个想法是我在这个球体的中心有一个物体,它的半径为 dz。 Since I know the 3d coordinate of the object I know all the 3d coordinates of the sphere.因为我知道对象的 3d 坐标,所以我知道球体的所有 3d 坐标。 Is it possible to determine the RPY of any point on the sphere such that the point always points toward the object in the center?是否可以确定球体上任何点的 RPY,使得该点始终指向中心的物体?

illustration:插图:

在此处输入图片说明

At the origo of this sphere we have an object.在这个球体的原点,我们有一个对象。 The radius of the sphere is dz.球体的半径为 dz。 The red dot is a point on the sphere, and the vector from this point toward the object/origo.红点是球体上的一个点,以及从这个点到物体/原点的向量。

The position should be relatively easy to extract, as a sphere can be described by a function, but how do I determine the vector, or rotation matrix that points such that it points toward origo.位置应该相对容易提取,因为一个球体可以用一个函数来描述,但是我如何确定指向原点的向量或旋转矩阵。

You could, using the center of the sphere as the origin, compute the unit vector of the line formed by the origin to the point on the edge of the sphere, and then multiply that unit vector by -1 to obtain the vector pointing toward the center of the sphere from the point on the edge of the sphere.您可以使用球体的中心作为原点,计算由原点到球体边缘上的点所形成的直线的单位向量,然后将该单位向量乘以 -1 以获得指向该点的向量从球体边缘的点到球体的中心。

Example:例子:

vec pointToCenter(Point edge, Point origin) {
    vec norm = edge - origin;

    vec unitVec = norm / vecLength(norm);

    return unitVec * -1;
}

Once you have the vector you can convert it to euler angles for the RPY, an example is here一旦你有你可以将其转换为RPY欧拉角载体,一个例子是在这里

Of the top of my head I would suggest using quaterneons to define the rotation of any point at the origin, relative to the point you want on the surface of the sphere:在我的头顶,我建议使用四元数来定义原点处任何点的旋转,相对于球体表面上你想要的点:

  1. Pick the desired point on the sphere's surface, say the north pole for example在球体表面选择所需的点,例如北极
  2. Translate that point to the origin (assuming the radius of the sphere is known), using 3D Pythagorus: x_comp^2 + y_comp^2 + z_comp^2 = hypotenuse^2使用 3D 勾股法将该点平移到原点(假设球体的半径已知):x_comp^2 + y_comp^2 + z_comp^2 = 斜边^2
  3. Create a rotation that points an axis at the original surface point.创建将轴指向原始曲面点的旋转。 This will just be a scaled multiple of the x, y and z components making up the hypotenuse.这只是构成斜边的 x、y 和 z 分量的缩放倍数。 I would just make it into unit components.我会把它做成单元组件。 Capture the resulting axis and rotation in a quaterneon (q, x, y, z), where x, y, z are the components of your axis and q is the rotation about that axis.在四元数 (q, x, y, z) 中捕获生成的轴和旋转,其中 x, y, z 是轴的分量,q 是绕该轴的旋转。 Hard code q to one.硬编码 q 到 1。 You want to use quaterneons because it will make your resulting rotation matricies easier to work with你想使用四元数,因为它会让你的旋转矩阵更容易使用
  4. Translate the point back to the sphere's surface and negate the values of the components of your axis, to get (q, -x, -y, -z).将点转换回球体的表面并取反轴分量的值,以获得 (q, -x, -y, -z)。
  5. This will give you your point on the surface of the sphere, with an axis pointing back to the origin.这将为您提供球体表面上的点,轴指向原点。 With the north pole as an example, you would have a quaternion of (1, 0, -1, 0) at point (0, radius_length, 0) on the sphere's surface.以北极为例,您将在球体表面上的点 (0, radius_length, 0) 处有一个 (1, 0, -1, 0) 的四元数。 See quatrotation.c in my below github repository for the resulting rotation matrix.有关生成的旋转矩阵,请参阅我下面的 github 存储库中的 quatrotation.c。

I don't have time to write code for this but I wrote a little tutorial with compilable code examples in a github repository a while back, which should get you started:我没有时间为此编写代码,但不久前我在 github 存储库中编写了一个带有可编译代码示例的小教程,这应该可以帮助您入门:

https://github.com/brownwa/opengl https://github.com/brownwa/opengl

Do the mat_rotation tutorial first, then do the quatereons one.先做 mat_rotation 教程,然后做 quatereons 一。 It's doable in a weekend, a day if you're focused.如果您专心,则可以在周末或一天内完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM