0
\$\begingroup\$

How do you get the Euler Angles of Euler Angles of Any Great Circle that surrounds the raycast hit.point of a sphere?

\$\endgroup\$
1
  • \$\begingroup\$ Hi, it's a bit unclear what you are talking about. Can you be more descriptive about the angles and the "great circle" in your example? Since you mentioned hit.point, are you trying to solve a problem using a certain engine? If so, please add this information to your question and you'll help us answer your question. \$\endgroup\$
    – liggiorgio
    May 28, 2021 at 10:59

1 Answer 1

1
\$\begingroup\$

I'm going to assume you're using Unity's coordinate system and Euler angle conventions. I'm also going to assume you have a "reference" great circle model as a child of the sphere, which in its default rotation (local Euler angles 0,0,0) lies along the equator of the sphere in the local XZ plane, with its pivot at the center. I'll assume you want a set of local Euler angles that rotate this child circle model to pass through a particular hit point on its parent.

If any of these assumptions are incorrect, then let this be a lesson to include those details in your question so we don't have to guess. 😜

First we'll transform the hit point into the sphere's local coordinates and normalize it, to eliminate the influence of the parent's transformation.

var localHitDirection = sphere.transform.InverseTransformPoint(hit.point).normalized;

Now we can make our yaw and pitch angles by converting this point into spherical coordinates in the usual way.

float yaw = Mathf.Atan2(localHitDirection.x, localHitDirection.z) * Mathf.Rad2Deg;

float pitch = -Mathf.Asin(localHitDirection.y) * Mathf.Raf2Deg;

Using these two angles will ensure the point on the great circle at (0, 0, 1) rotates to lie along the line joining the sphere's center to the hit point.

Our roll angle is a degree of freedom you get to choose. Choosing any angle -180 to +180 will spin the great circle around this line, keeping it passing through the hit point on the rotation axis while the rest of the circle sweeps around the sphere.

Once you've chosen your roll angle, you can apply your rotation as:

greatCircle.transform.localEulerAngles = new Vector3(pitch, yaw, roll);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .