calculating position on a sphere

Started by
9 comments, last by GameDev.net 19 years, 2 months ago
This can be done very easily using just normal cartesian cordinates. All you have to know is how to add two vectors and how to do a cross product. Let me explain.

Assume you have a vector that tells the position of the man on the sphere (p). You also need a vector to store the direction (d). Clearly, there is a problem with possible corrupt vectors but we'll deal with that later.

Assume you man moves 'forward' a radians. (This equals a length of a/(2Pi)*R .) All you have to do is modify the position and forward vectors. Look at the following speudo code and see if it makes some sense.

pn=cos(a)*p+sin(a)*d; // new position
dn=cos(a)*d-sin(a)*p; // new direction
p=pn; // set 'em
d=dn;

How do you change the direction of the man then? We'll, you might want calculate the vector that points 'right' (or why not left) using the vector cross product. Then you modify the direction vector in basically the same way.

This topic is closed to new replies.

Advertisement