# Controlling an object orbiting a sphere

I want to let the user control an object moving over the surface of a static sphere. Using two buttons to rotate the direction of the object clockwise and anti-clockwise as it constantly moves forward similar to asteroids.

In scene kit there are three different orientation properties for an SCNNode and I really don’t know where to start. I understand how to execute everything except the rotation around the sphere.

- How to implement a “rate us” feature in a phonegap app
- Max size of WebSQL/SQLite database inside UIWebView (phonegap)
- How to disable iOS System Sounds
- How to redirect towards GPS setting window in android or ios using phonegap for on or off a GPS
- Textured Line in CG
- Swift: Cannot convert value of type 'Int16' to expected argument type 'AnyObject?'

### Solutions Collect From Internet About “Controlling an object orbiting a sphere”

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

The surface of the sphere is parameterized by two angle variables, call them `s`

and `t`

. Note that one variable will run from zero to 2 pi, and the other will run only from zero to pi. This is a gotcha that can be easy to miss. 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's sin(t) twice, that's not a typo.
z = r cos(t)
```

I find the following visualization helpful. A curve in a plane (the xy-plane, for example) sweeps out an angle from zero to pi, half a rotation and corresponds to the parameter `s`

. If you set `t`

equal 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 `s`

parameter sweeps out half a circle, you can rotate that half circle *all the way around* from zero to 2 pi, to form a full sphere, and that full sweep corresponds to the parameter `t`

.

If you represent your object’s position by 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 either parameter; however if `s`

or `t`

grow without bound (say, because your object orbits continuously for a long time) it might be worth the small extra effort to normalize the parameters. I’m not sure how `sin`

or `cos`

behave for very large inputs.

- renderincontext Memory Leak if not use on Main thread
- How to detect all touches in Swift 2
- SWIFT – Show Current Location and Update Location in a MKMapView
- NSUndoManager casting NSUndoManagerProxy crash in Swift code
- pushViewController Taking too much to show the view
- Converting NSString to Base64 Data for XML Serialization
- iPhone: NSDate convert GMT to local time
- How do I capture a zoomed UIImageView inside of a Scrollview to crop?
- Swift iOS Client Certificate Authentication
- Is it possible to show a tooltip in an iOS app?
- Swift Unit test- How do I assert that a CGColor is what it's supposed to be?
- iOS: GPPSignInButton always asks for “Have offline access” Permission
- Broadcast data to multiple widgets in Flutter
- How to fix C-style for statement?
- Can't read from plist