Take the 2-minute tour ×

I've read somewhat over 300 pages on the internet, and I didn't get the result I wanted or either it didn't work, so I hope people can help me out over here. You can explain by using pseudo code and maths. :)

So, we have point A (which is the origin). Point A has a radius, an XYZ position and XYZ rotation (I know it can be done with 2 angles, but I really need it to be with 3 angles). Point B's position is unknown.

Armed with that information, my question is: how would I find the position of point B? (Alternatively, my question could be rephrased as: "how to find a 3D point on a sphere?")

I've already done it in 2D and there it worked. for 2D I used:


I don't use pure matrices but I want to use cosines and such. My attempt (which fails badly, I really have no idea how to combine XYZ rotations with cosines) in pseudo code:


I would appreciate it so much if someone could help me. :)

share|improve this question

3 Answers 3

up vote 0 down vote accepted

Suppose that you have a sphere centered at the origin, with known radius, and azimuth and elevation angles. Then you can simply find cartesian coordinates using spherical to cartesian conversion.

So, first take relative B components, with the A radius and your angles. You obtain cartesian components. Then, you can add these relative components to A cartesian components, returning absolute B coordinates. Don't consider the roll angle, because for a point it's useless.

share|improve this answer
Thanks, normally I don't understand those equations on wikipedia, but now I was able to implement it into my 3d environment. It did rotate succesfully with only 2 angles. But I'm still not sure if I should use XY or ZX, etc.? –  user1569781 Aug 6 '12 at 11:33
There are conventions. You can use the convention you want, but remember to be consistent with it then (use always the same convention if you can). If you don't know about this, use the ZYX convention. –  Jepessen Aug 18 '12 at 6:58

x = cos(yaw) * cos(pitch)

y = sin(yaw) * cos(pitch)

z = sin(pitch)

Roll not needed.

This isn't perfect I don't think? Radians are needed and that could be a source of error. I believe you have to get all Quaternion or incorporate roll but it can be sufficient for an intermediate solution.

In a recent situation I negated cos of pitch for x = cos(yaw) * -cos(pitch)

share|improve this answer

Thanks for the answers. I know that it's a long time ago that this question was answered, but for the sake of people reading this, I will share my implementation. So here it is, in Lua; the PointOnSphere function with two input angles (the azimuth and altitude are the same as rotation.x and rotation.y) (in degrees):

function PointOnSphere(origin,rotation,radius)
return {x=origin.x+radius*math.cos(math.rad(rotation.y))*math.cos(math.rad(rotation.x)),y=origin.y+radius*math.sin(math.rad(rotation.x)),z=origin.z+radius*math.sin(math.rad(rotation.y))*math.cos(math.rad(rotation.x))}

Note that this answer is relevant when using a coordinate system where the y-axis points up.

An additional useful link is this one, it's the same question with similar answers: http://math.stackexchange.com/questions/264686/how-to-find-the-3d-coordinates-on-a-celestial-spheres-surface

share|improve this answer

Your Answer


