简体   繁体   中英

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. Since I know the 3d coordinate of the object I know all the 3d coordinates of the sphere. 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?

illustration:

在此处输入图片说明

At the origo of this sphere we have an object. The radius of the sphere is 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.

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

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
  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. 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. Hard code q to one. 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).
  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. See quatrotation.c in my below github repository for the resulting rotation matrix.

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:

https://github.com/brownwa/opengl

Do the mat_rotation tutorial first, then do the quatereons one. It's doable in a weekend, a day if you're focused.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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