Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Velocity on a sphere

  1. Feb 27, 2009 #1
    Hello all,

    I am writing a program/game where you can move on a sphere's surface (like you are walking the earth). So I want to tell my object "move 10 meters in that direction", with a velocity-vector. The z-coordinate will never be used so I can construct this vector as:

    vx = speed * cos(angle)
    vy = speed * sin(angle)
    vz = 0

    The object is placed on the sphere with:

    x = radius * cos(lat) * cos(lon)
    y = radius * cos(lat) * sin(lon)
    z = radius * sin(lat)

    Now I want to know the new coordinates (cartesian or spherical) after the object has moved.
    I've been aware of the formula's in the attached image. But i don't quite know how to use them.

    Thanks in advance.

    Attached Files:

  2. jcsd
  3. Feb 27, 2009 #2


    User Avatar
    Gold Member

    Well the spherical coordinate system I know of is the same as what the image says. So any new coordinates should have any new spherical coordinates [tex]\theta_{0}+\theta[/tex] and [tex]\phi_{0}+\phi[/tex]. What you have there is a conversion to cartesian. I really don't see anything complicated there. Just calculate each vector component separately to keep things simple.
  4. Feb 27, 2009 #3
    Your expression for z is based on the latitude angle (actually all of your expressions involve the latitude) whereas the standard polar forms shown in the figure are based on the colatitude angle. This could cause you some confusion, so be carefule.
  5. Mar 1, 2009 #4
    No, it's not that I want to give new spherical coordinates. I've written some pseudo-code about the concept. So I have a latitude and longitude and convert it to cartesian coordinates. Then I want to shift the xyz to a new place with the velocity vector (vx, vy, vz). It places my object on the sphere and then I convert the new position to spherical coordinates. When the loop starts again, my current position is changed and I can move it again and again.


    x = R * cos(lat) * cos(lon);
    y = R * cos(lat) * sin(lon);
    z = R * sin(lat);

    x = x + vx;
    y = y + vy;
    z = z + vz;

    place_object(x, y, z);

    lat = atan(sqrt(x*x + y*y), z);
    lon = atan(y, x);


    This code will not work, because the object will not stay on the sphere's surface. Therefore I think I must implement the unit vectors, but I don't know for sure, and how. I hope it brings some clearness in my problem.

    Thank you for replying.
    Last edited: Mar 1, 2009
  6. Mar 1, 2009 #5
    Hi sumerian

    At one point you have:

    x = x + vx;
    y = y + vy;
    z = z + vz;

    which in general will move the object off of the surface. If you want to stay on the surface then you need

    lon = lon + vlon
    lat = lat + vlat

    where vlon and vlat are given by:

    vlon = -vx sin(lon) + vy cos(lon)
    vlat = vx cos(lon)cos(lat) + vy sin(lon)cos(lat) - vz sin(lat)

    which I obtained from the angular unit vectors in your attached diagram.
  7. Mar 2, 2009 #6
    Each move is rotating the position vector in the direction of v, right?

    a=distance/R % angle travelled around sphere, in radians
    r1=cos(a)*r+sin(a)*R*(v/V) % new position
    v1=-sin(a)*V*(r/R)+cos(a)*v % new velocity
  8. Mar 2, 2009 #7

    That was exactly what I was trying to implement. The object moves along the sphere's surface with the speed and angle I give it. But when it approaches the poles it seemes to slow down and on the "equator" it's very fast and unstable. I tried to tweak it a little bit, computers offenly switches sin and cos, but that didn't do any good. I think the problem lies in the unit vectors. I'll keep testing that. Anyway, thank you very much. I appreciate the help.


    I also tried to implement your contribution to the problem but that gave me some strange results. The new velocity that you calculated, I don't think I could use it, do I? This is the code I use for it, correct me if I'm wrong:

    vx = speed * cos(angle);
    vy = speed * sin(angle);
    vz = 0;

    x = radius * cos(lat) * cos(lon);
    y = radius * cos(lat) * sin(lon);
    z = radius * sin(lat);

    R = sqrt(x*x + y*y + z*z);
    V = sqrt(vx*vx + vy*vy + vz*vz);

    a = speed/R;

    x = cos(a) * x + sin(a) * R * vx / V;
    y = cos(a) * y + sin(a) * R * vy / V;
    z = cos(a) * z + sin(a) * R * vz / V;

    lat = atan2(sqrt(x*x + y*y), z);
    lon = atan2(y, x);

    Thank you for your help.


    I found a formula for the velocity on a sphere, is this usefull? : attached.

    Attached Files:

    Last edited: Mar 2, 2009
  9. Mar 2, 2009 #8
    I'll let you know if I think of anything, but for now you should also make sure that you are using radians rather than degrees, at least for the method that I outlined.
  10. Mar 2, 2009 #9
    The velocity vector has to be orthogonal to the position vector.
  11. Mar 6, 2009 #10

    I uploaded my project with the 2 different implementations:

    http://sumerian.50webs.com/test1.html" [Broken]
    http://sumerian.50webs.com/test2.html" [Broken]

    bpet's code has the same affect as confinement's code. It works but they slow down when approaching the "equator" (bpet) or the "poles" (confinement). On the bottom of the page you can see the code i used. (Actionscript) Click on the sphere first (to focus on the flash-object) and then you can move around. If you are stuck on the poles or equator, refresh your page.

    There is a difference between the positioning of the 2. One uses cos(lat) where the other uses sin(lat). If I change them, the results are even more dramatic.

    The speed has a difference to. On test1 (bpet) the speed is set to 50, test2 (confinement) has a speed of 0.05.

    Do you have any suggestions about the slowing-down-areas.

    Thank you
    Last edited by a moderator: May 4, 2017
  12. Mar 6, 2009 #11
    Your initial velocity is not at right angles to the position vector. It needs to be for the rotation method to work otherwise the point will move off the sphere. Choose an orthogonal initial velocity or use Gram-Schmidt on the one you've got.

  13. Mar 10, 2009 #12

    So I tried to work with the Gram-Schmidt process, to make my velocity vector orthogonal:

    var vx = speed*Math.cos(angle);
    var vy = speed*Math.sin(angle);
    var vz = 0;

    var proj = (vx*x + vy*y + vz*z)/(radius*radius); // (x*x + y*y + z*z);

    vx = vx - proj*x;
    vy = vy - proj*y;
    vz = vz - proj*z;

    This is correct I suppose. Still The object slows down on the equator.

    When I search the internet, I only find information where they use unit vectors. This formula of yours, bpet, can I find some more information about it on the net?

  14. Mar 10, 2009 #13
    That looks right. To convince yourself check that the dot product is zero. Also at each step are you rotating the velocity vector correctly?
  15. Mar 11, 2009 #14
    I solved one problem. I did not re-use the new velocity and position vectors. It comes down to this:



    Now the object moves smoothly along a great circle and stays onto the sphere. The problem now is, when I want to change the velocity, it loses its rotation. So I need to figure out a way to update the velocity in its current rotation.

    Thanks guys, you've been a great help so far. Almost there..
  16. Mar 11, 2009 #15
    Perhaps the cross product will be useful? Any change in velocity will be in the direction of +/- v or +/- (r x v).
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook