Calculating Velocity on a Sphere

In summary, the conversation discusses a program/game where objects can move on a sphere's surface using velocity-vectors. The formula for constructing the velocity-vector is given, as well as the formula for placing the object on the sphere's surface. The conversation also mentions implementing unit vectors to keep the object on the surface, and provides code for calculating the new velocity and position of the object. However, there is some confusion about the velocity vector and its effects on the object's movement. The conversation concludes with the sharing of a project demonstrating the two different implementations and their resulting movements.
  • #1
sumerian
6
0
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.
 

Attachments

  • sphere.jpg
    sphere.jpg
    24.2 KB · Views: 721
Physics news on Phys.org
  • #2
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.
 
  • #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.
 
  • #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.

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.

Thank you for replying.
 
Last edited:
  • #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.
 
  • #6
sumerian said:
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.

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


EDIT:

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

Attachments

  • spherevelocity.jpg
    spherevelocity.jpg
    2 KB · Views: 490
Last edited:
  • #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.
 
  • #9
sumerian said:
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);
z = radius * sin(lat);

The velocity vector has to be orthogonal to the position vector.
 
  • #10
okay,

I uploaded my project with the 2 different implementations:

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

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:
  • #11
sumerian said:
Do you have any suggestions about the slowing-down-areas.

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
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
sumerian said:
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

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
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
sumerian said:
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.

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

1. How is velocity on a sphere calculated?

Velocity on a sphere is calculated using the formula v = rω, where v is velocity, r is the radius of the sphere, and ω is the angular velocity.

2. What is the difference between linear velocity and angular velocity?

Linear velocity refers to the speed at which an object is moving in a straight line, while angular velocity refers to the speed at which an object is rotating around a central axis.

3. Can velocity be negative on a sphere?

Yes, velocity can be negative on a sphere. Negative velocity indicates that the object is moving in the opposite direction of the chosen reference point.

4. How does the radius of the sphere affect velocity?

The radius of the sphere directly affects the velocity, as the formula v = rω shows. A larger radius will result in a higher velocity, while a smaller radius will result in a lower velocity.

5. Is it possible to have a constant velocity on a sphere?

Yes, it is possible to have a constant velocity on a sphere. This would occur if the angular velocity is constant and the object is moving in a circular path with a constant radius.

Similar threads

Replies
3
Views
641
  • Calculus
Replies
15
Views
2K
Replies
11
Views
5K
  • Advanced Physics Homework Help
Replies
4
Views
370
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
1
Views
974
Replies
2
Views
1K
Replies
12
Views
2K
Back
Top