# Velocity on a sphere

1. Feb 27, 2009

### sumerian

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)

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.

#### Attached Files:

• ###### sphere.jpg
File size:
41.7 KB
Views:
165
2. Feb 27, 2009

### djeitnstine

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 $$\theta_{0}+\theta$$ and $$\phi_{0}+\phi$$. 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.

3. Feb 27, 2009

### Dr.D

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.

4. Mar 1, 2009

### sumerian

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.

loop(

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.

Last edited: Mar 1, 2009
5. Mar 1, 2009

### confinement

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.

6. Mar 2, 2009

### bpet

Each move is rotating the position vector in the direction of v, right?

r=[x,y,z]
R=sqrt(r.r)
v=[vx,vy,vz]
V=sqrt(v.v)
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

7. Mar 2, 2009

### sumerian

confinement,

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.

bpet,

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);

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);

EDIT:

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

#### Attached Files:

• ###### spherevelocity.jpg
File size:
2 KB
Views:
111
Last edited: Mar 2, 2009
8. Mar 2, 2009

### confinement

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.

9. Mar 2, 2009

### bpet

The velocity vector has to be orthogonal to the position vector.

10. Mar 6, 2009

### sumerian

okay,

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
11. Mar 6, 2009

### bpet

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.

HTH

12. Mar 10, 2009

### sumerian

Hello,

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?

Thanks

13. Mar 10, 2009

### bpet

That looks right. To convince yourself check that the dot product is zero. Also at each step are you rotating the velocity vector correctly?

14. Mar 11, 2009

### sumerian

I solved one problem. I did not re-use the new velocity and position vectors. It comes down to this:

r=[x,y,z]
R=sqrt(r.r)
v=[vx,vy,vz]
V=sqrt(v.v)
a=distance/R

loop(
r1=cos(a)*r+sin(a)*R*(v/V)
v=-sin(a)*V*(r/R)+cos(a)*v
r=r1
)

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..

15. Mar 11, 2009

### bpet

Perhaps the cross product will be useful? Any change in velocity will be in the direction of +/- v or +/- (r x v).