Calculating rotations required to

46 Views Asked by At

I have a situation similar to a question asked on StackOverflow with the following image: From: https://stackoverflow.com/q/30011741

I have an object that rests at the tip of the green arrow (point XYZ), and I'm using the following formulas to determine it's position based on alpha and beta:

        x = Distance * Mathf.Cos(alpha)*Mathf.Sin(beta)
        z = Distance * Mathf.Sin(alpha)*Mathf.Sin(beta)
        y = Distance * Mathf.Cos(beta)

But how would I find alpha and beta given point XYZ? I also need to find distance, but I assume that would just be the distance from the tip of XYZ to the origin.

1

There are 1 best solutions below

0
On

What you are using is known as "Spherical Coordinates", where what you call the "distance" is written as the radius $r$, "alpha" is the angle $\theta$, and "beta" is the angle $\phi$. We then apply the Cartesian to Spherical formulas
$$r = \sqrt{x^2 + y^2 + z^2}$$ $$\theta = \arctan\left(\frac{y}{x}\right)$$ $$\phi = \arccos\left(\frac{z}{r}\right)$$
(Note that the formula for $\phi$ is condensed by substituting in the definition of $r$. Also, see here for more info on Spherical Coordinates! Also, if you want more understanding as to how we get these formulas, check out this site, which doesn't directly give each of these but explains how each is derived [the page assumes you know about cylindrical coordinates; if not, check that out also... the same site has a great explanation!])