How Can I add Latitude, Longitude dynamically in Javascript?

How can I represent motion vectors on the surface of a sphere and add them together?

  • I'm making a planet simulator, which makes much use of a sphere. Currently, I use latitude/longitude pairs for coordinates on the sphere, which have been fine for things like calculating distances and projecting the sphere to a rectangle; however, I'm not sure how to represent motion on the sphere (i.e. vectors) and how to add these vectors to produce new coordinates.  I'm completely open to not using latitude/longitude if that makes the job easier. I'm using a sphere of radius 1 to simplify calculation.

  • Answer:

    Motion of points on the surface of a sphere is analogous to angular motion in the 3D space around the origin. An angular motion can be represented by http://en.wikipedia.org/wiki/Angular_velocity, which is a 3D vector. If the direction of movement is perpendicular to the point's displacement from the origin (which is always the case if the point is moving along the surface of a sphere), angular velocity has the formula [math]\vec{\omega} = \frac{d\phi}{dt} \vec{u} = \frac{v}{r} \vec{u}[/math] where [math] \frac{d\phi}{dt} [/math] is the angular speed (the speed in radian the point is rotating), [math]\vec{u}[/math] is the axis of rotation (using right-hand rule, normalized to unit length). It can also be expressed in its speed of motion on the surface of the sphere [math]v[/math], and the radius of the sphere [math]r[/math]. When a point undergoes two angular motions [math]\vec{\omega}_1,\vec{\omega}_2[/math] (or the point is rotating at [math]\vec{\omega}_1[/math] relative to the sphere, and the sphere is itself rotating at [math]\vec{\omega}_2[/math]), the resultant angular velocity just adds up to  [math]\vec{\omega}_1+\vec{\omega}_2[/math]. To find the position of a point [math]\vec{x}[/math] after rotating by [math]\vec{\omega}[/math] for time [math]t[/math], you may first convert the angular velocity to axis-angle representation (the axis of rotation is [math]\vec{\omega}/\left\Vert \vec{\omega}\right\Vert [/math], and the angle of rotation is [math]t \left\Vert \vec{\omega}\right\Vert [/math]), then use the http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula to obtain the resultant position. Note that the lat/long has to be converted to Cartesian coordinates to apply these formulas. Using Cartesian coordinates usually gives you simpler formulas.

Ivan Li at Quora Visit the source

Was this solution helpful to you?

Other answers

Assume every vector on the surface of a sphere is the short part of a Great Circle.  Then if you have vector A tail to nose butting on vector B's tail,  You find the great circle segment connecting the tail of A to the nose of B.  You have now made a vector triangle.

Robert J. Kolker

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.