Controlling an object revolving around a sphere

I want the user to be able to control an object moving across the surface of a static sphere. Using the two buttons to rotate the direction of an object clockwise and counterclockwise as it constantly moves forward, like asteroids.

There are three different orientation properties for the SCNNode in the plot set and I really don't know where to start. I understand how to do everything except rotation around the sphere.

+3


source to share


1 answer


You are looking for parametrizing the surface of a sphere. You can find this online (but it can be tricky if you don’t know what magic words to type for your searches). Check the entry on MathWorld .

The surface of the sphere is parameterized by two angular variables, name them s

and t

. Note that one variable will work from zero to 2 pi and the other will only work from zero to pi. This is something that can be easily missed. To convert these angles to rectangular (x, y, z) coordinates, you use the formula:

x = r cos(s) sin(t)
y = r sin(s) sin(t) // Yes it sin(t) twice, that not a typo.
z = r cos(t)

      



I find the following visualization helpful. A curve in a plane (for example, the xy plane) sweeps an angle from zero to pi by half a turn and matches the parameter s

. If you set it t

to pi / 2, so sin (t) = 1, then you can see how x and y turn into standard rectangular coordinates for a circular section. After the parameter s

sweeps out half of the circle, you can rotate that half circle around zero from zero to 2 pi to form a full sphere, and the full sweep matches the parameter t

.

If you represent your object's position in coordinates (s, t)

, then you can, for the most part, safely convert to rectangular coordinates using the formula above without worrying about the domain of any parameter; however, if s

or t

grow without constraints (for example, because your object is spinning continuously for a long time), it may take a little extra effort to normalize the parameters. I'm not sure how sin

or cos

behave for very large inputs.

+3


source







All Articles