0

I have a point on a sphere that needs to be rotated. I have 3 different degrees of rotation (roll, pitch, yaw). Are there any formulas I could use to calculate where the point would end up after applying each rotation? For simplicity sake, the sphere can be centered on the origin if that helps.

I've tried looking at different ways of rotation, but nothing quite matches what I am looking for. If I needed to just rotate the sphere, I could do that, but I need to know the position of a point based on the rotation of the sphere.

Using Unity for an example, this is outside of unity in a separate project so using their library is not possible:

If the original point is at (1, 0, 0) enter image description here

And the sphere then gets rotated by [45, 30, 15]: enter image description here What is the new (x, y, z) of the point?

Blast
  • 21
  • 4

1 Answers1

0

If you have a given rotation as a Quaternion q, then you can rotate your point (Vector3) p like this:

Vector3 pRotated = q * p;

And if you have your rotation in Euler Angles then you can always convert it to a Quaternion like this (where x, y and z are the rotations in degrees around those axes):

Quaternion q = Quaternion.Euler(x,y,z);

Note that Unity's euler angles are defined so that first the object is rotated around the z axis, then around the x axis and finally around the y axis - and that these axes are all the in the space of the parent transform, if any (not the object's local axes, which will move with each rotation).

So I suppose that the z-axis would be roll, the x-axis would be pitch and the y axis would be yaw.You might have to switch the signs on some axes to match the expected result - for example, a positive x rotation will tilt the object downwards (assuming that the object's notion of forward is in its positive z direction and that up is in its positive y direction).

  • Unfortunately I’m outside of Unity in a project where using a library is not necessarily possible. Do you know what these are doing under the hood? – Blast Jan 27 '23 at 15:56
  • Ahh, I see. You could maybe try to have a look at this answer: https://stackoverflow.com/a/14609567/17417673 Essentially I guess you are trying to rotate a 3D vector (position) by some rotation defined in Euler angles (sequential rotation around the 3 axes). The post answer uses matrices that they multiply by the vector. If matrices are new territory they might seem scary, but multiplying a matrix by a vector is really just a defined way of multiplying the elements together to form a new matrix or vector (in this case, a new vector). – Jakob Hougaard Andersen Jan 31 '23 at 08:33