# Velocity along the surface of a sphere

This topic is 2811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I want to move an object along the surface of a sphere with a given velocity. I essentially want to make a simple tether airplane simulator (control line). I know that I need to work in spherical coordinates for the position of the object and its velocity. This is what I have so far.

I initially get the position of the object. Theta and Phi are initially zero and Radius = 2; Therefore the polar to opengl result is (0,0,2);

void init()
{
//position from polar to opengl
pos.x = Radius * sin(theta) * sin(phi);
pos.z = Radius* cos(theta) * sin(phi);
}

The velocity must be orthogonal to the position vector.

void update()
{
//update velocity

//ensure velocity is orthogonal to position
velocity.x = velocity.x - proj * pos.x;
velocity.y = velocity.y - proj * pos.y;
}

I have calculated the local axis of the object. How can I apply this velocity vector to my object to ensure that it remains on the sphere and the speed remains constant around the poles and equator?

Thanks

##### Share on other sites
Actually in this case using spherical coordinates could make things more complicated. You are probably better off working in tangent space for a timestep and then renormalizing the result,

##### Share on other sites
Isn't it sufficient to just update theta and phi ?

Update:

theta += speed.x;
phi += speed.y;

pos.x = Radius * sin(theta) * sin(phi);
pos.z = Radius* cos(theta) * sin(phi);

##### Share on other sites
Alternatively, you might want to take a look at slerping.

-Josh

##### Share on other sites
Molle85.

I had the same idea. Unfortunately the object slows down around the poles. I think it is because the lines of longitude are closer at the poles but I'm not sure how I am going to get around it.

//position object
position.z = radius * cos(theta) * sin(phi);
position.x = radius * sin(theta) * sin(phi);

//update velocity vector

lon += velocity.x;
lat += velocity.y;

Any suggestions would be appreciated.

Thanks

##### Share on other sites
I did it with quaternions once.

I'm no math wiz, but it felt like a neat sollution.

One quat to define the position (including rotation on the tangent plane), and another for the speed.
just multiply the speed quat with the pos quat and renormalize.
for turning, rotate the position quat around its own axis, and create a new speed quat.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 12