SCNSphere - XYZ orientation appears wrong?

Hi,


I've asked on StackOverflow and not had an answer which helps, so I thought it best to ask here. I have a sphere with a texture of the earth. Everything appears correct. If I draw a point on that sphere using latitude and longitude, I have to switch around XYZ in order for the object to appear in the correct location.


I am using the following to translate lat and lon:-

LAT = latitude * pi/180

LON = longitude * pi/180

x = -R * cos(LAT) * cos(LON)

y = R * sin(LAT)

z = R * cos(LAT) * sin(LON)

My method for translating the points is as follows: -


-(SCNVector3) vectorFromCoordinate:(GLfloat)lat lon:(GLfloat)lon distance:(GLfloat)radius

{

SCNVector3 result;

lat = DEGREES_TO_RADIANS(lat);

lon = DEGREES_TO_RADIANS(lon);


result.z = cos(lat) * cos(lon) * radius;

result.x = cos(lat) * sin(lon) * -radius;

result.y = sin(lat) * radius;


return result;

}


As you can see, the formula for X is used to calculate Z, the forumla to calculate Y is used to calcuate X and the formula to calculate Z is used to calculate Y. I haven't done anything out of the ordinary, I've simply created a sphere with a radius and added it to a scene's root node... so my question is, why am I having to use XYZ as ZXY in order to plot at the correct location?

Where did you find your formula ? Maybe it assumes the z axis points toward the back of the scene.

Here's what I have in my code; I've determined the formula myself:


CGFloat sinLong = sin(RAD_FROM_DEG(coordinate.longitude));
CGFloat cosLong = cos(RAD_FROM_DEG(coordinate.longitude));
CGFloat sinLat = sin(RAD_FROM_DEG(coordinate.latitude));
CGFloat cosLat = cos(RAD_FROM_DEG(coordinate.latitude));
    
vertex = SCNVector3Make(radius*sinLong*cosLat,
                        radius*sinLat,
                        radius*cosLong*cosLat);


I know it works for sure.

The formula can be found on many different websites and are definitely correct. Yours are effectively the same as mine with some optimisation.


This means you too are using the formula in the wrong order - but getting the correct results?

No, my formula is different, as your x is multiplied by MINUS radius. I did not came up with it by trial and error, but by drawing and thinking

It looks like DirectX uses a left-handed coordinate system, whereas it is right-handed in Scene Kit.

Maybe the formula you found is a for a left-handed coordinate system.

I hadn't considered that - I suspect you may be correct. I'll look into it - thanks ElRhino.

SCNSphere - XYZ orientation appears wrong?
 
 
Q