Jump to content
  • Advertisement
Sign in to follow this  
Phantom805

Velocity along the surface of a sphere

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

If you intended to correct an error in the post then please contact us.

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.y = Radius * cos(phi);
pos.z = Radius* cos(theta) * sin(phi);
}

The velocity must be orthogonal to the position vector.

void update()
{
//update velocity
velocity.x = speed*cos((heading));
velocity.y = speed*sin((heading));

//ensure velocity is orthogonal to position
float proj = (velocity.x * pos.x + velocity.y* pos.y + 0*pos.z)/(Radius*Radius);
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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.y = Radius * cos(phi);
pos.z = Radius* cos(theta) * sin(phi);

Share this post


Link to post
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);
position.y = radius * cos(phi);

//update velocity vector
velocity.x = speed*cos(heading);
velocity.y = speed*sin(heading);

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

Any suggestions would be appreciated.

Thanks

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!