How to calculate the position on a sphere. Usefull to get something to rotate around a point other than it's center, among other things.

vector spherePos(vector offset, float radius, float zenith, float azimuth) { // zenith is the angle between the positive z-axis and the vector. Ranges from 0 to PI. 0 will put the object at the top of the sphere, PI will put it at the bottom. This represents a horizontal slice of the sphere, the height the object will be placed at. // azimuth is the angle between the positive x-axis and the vector projected onto the xy-plane. Ranges from 0 to TWO_PI. 0 or TWO_PI will put the object at the positive radius for x and 0 for y. This is how far around the horiztonal sphere-slice determined from the zenith the object will be placed at. // see http://en.wikipedia.org/wiki/Spherical_coordinates float sinzenith = llFabs(llSin(zenith)); float x = sinzenith * llCos(azimuth); float y = sinzenith * llSin(azimuth); float z = llCos(zenith); return offset + (radius * <x, y, z>); }

There are 3 comments on this page.
[Display comments/form]