I have a large sphere, with the player walking along the surface of it. I have my mouse look all set up, so the player can look in different directions. I have the player's position stored in a custom spherical coordinate class that determines position based on North/South and East/West components, with these components mod'ed so you can wrap around the sphere.
Given the direction the player is currently looking, I want to modify the player's spherical coordinates. That means translating a velocity vector pointing along the mouse look direction into an angular velocity in N/S and E/W terms (spherical coordinates).
At the moment, here's how I'm imagining it working:
First, I remove the up/down from the mouse look rotation. This gives me a direction that is in the plane tangent to the player's position on the sphere.
Second, the "up" vector for the player's camera is simply the normalized current position of the player.
Then I find the angular velocity, which is w = (velocityscalar * direction) cross (camera's up vector) / (sphere's radius)
The angular velocity is now basically in angle axis form. From this I need to convert to two component rotations, one along N/S and another along E/W. How do I do this?

**0**

# Converting a rotation to spherical coordinates

Started by Numsgil, Mar 11 2007 04:13 PM

10 replies to this topic

Sponsor:

###
#2
Members - Reputation: **501**

Posted 13 March 2007 - 01:22 AM

I'm still looking for an answer; I'm really stumped. I could extract yaw, pith, and roll elements, but I'm not sure how to use those to convert to a change in longitude/latitude.

Darwinbots - Artificial life simulation

###
#3
Members - Reputation: **1002**

Posted 13 March 2007 - 02:12 AM

Just glanced at it quickly, so might be incorrect, but the solution as I see it is pretty simple:

Setup the equation

Then project

Setup the equation

**v**=**w**X**r****v**is known,**r**is known,**w**is sought. Solve for**w**.Then project

**w**onto your axes to determine the contribution around the axes of interest.
Best regards, Omid

###
#4
Members - Reputation: **501**

Posted 13 March 2007 - 03:08 AM

Quote:

Original post by Omid Ghavami

Then projectwonto your axes to determine the contribution around the axes of interest.

Care to elaborate?

Darwinbots - Artificial life simulation

###
#5
Members - Reputation: **1002**

Posted 13 March 2007 - 03:47 AM

Quote:

Original post by NumsgilQuote:

Original post by Omid Ghavami

Then projectwonto your axes to determine the contribution around the axes of interest.

Care to elaborate?

Orthogonal projection of

**u**on

**v**!= 0 is given by

<u,v>u^{'}= ------v

|v|^{2}

EDIT: hmpf, bold text doesn't show inside code clause, too bad.

Where <

**a**,

**b**> is the inner product (dot product) and |

**v**| is the 2-norm, ie the length of vector.

EDIT: noticed the equation don't look that great (When is GD going to support LaTeX? [wink]), if it's unclear it says:

The inner product (dot product) between

**u**and

**v**divided by the squared norm of

**v**, unless

**v**is normalised in which case the divition will be by 1 and hence unnecessary. This will be a scalar which is then multiplied by the vector

**v**to produce the orthogonal projection of

**u**on

**v**, here donted

**u**

^{'}

Best regards, Omid

###
#6
Members - Reputation: **1002**

Posted 13 March 2007 - 04:07 AM

Maybe I should also explain why it is so, it sucks to just be handed equations without explanation [smile]

<u, v> = |u| * |v| * cos(a)

Where a is the angle between the vectors. Now what's interesting here is that we see the term |u| * cos(a), which by trigonometry we know will be the component of u in v's direction.

So if we now divide <u, v> by |v| we get |u| * cos(a), which is u magnitude in v's direction. This is however a scalar value but we want a vector. So we want a vector in v's direction whose magnitude is |u| * cos(a). So we normalise v by dividing it with |v| and then multiply the normalized vector with |u| * cos(a).

The end result is as stated earlier

<u, v> / |v| * v / |v| = <u, v> v / |v|

<u, v> = |u| * |v| * cos(a)

Where a is the angle between the vectors. Now what's interesting here is that we see the term |u| * cos(a), which by trigonometry we know will be the component of u in v's direction.

% u

/

/

/) a

------> v

So if we now divide <u, v> by |v| we get |u| * cos(a), which is u magnitude in v's direction. This is however a scalar value but we want a vector. So we want a vector in v's direction whose magnitude is |u| * cos(a). So we normalise v by dividing it with |v| and then multiply the normalized vector with |u| * cos(a).

The end result is as stated earlier

<u, v> / |v| * v / |v| = <u, v> v / |v|

^{2}
Best regards, Omid

###
#7
Members - Reputation: **501**

Posted 13 March 2007 - 04:33 AM

It's not the math for the projection that's throwing me, it's

The issue is also complicated by the fact that facing North on the equator, and facing north 1 mm from the North Pole, give almost orthogonal directional vectors in euclidean space. But they are the same direction in geodesic space (that is, the topology of the surface of a sphere). Very confusing.

What's really happening is that the rotation is being defined by the player's position on the sphere. The great circle that passes through the player's position and is parallel in direction to the player's direction at the player's position forms the forward/backward rotation. The great circle perpindicular to this forms the left/right rotation. The forward/backward great circle probably coudl be corresponded pretty well to longitude. Both are great circles.

Latitude is not built from great circles. So I don't think an easy correspondance exists.

I dunno, the whole thing just stumps me.

*what*to project on to. There are 3 possible planes of interest. z = 0, y = 0, and x = 0. I have only 2 terms, phi and theta (or longitude and latitude).The issue is also complicated by the fact that facing North on the equator, and facing north 1 mm from the North Pole, give almost orthogonal directional vectors in euclidean space. But they are the same direction in geodesic space (that is, the topology of the surface of a sphere). Very confusing.

What's really happening is that the rotation is being defined by the player's position on the sphere. The great circle that passes through the player's position and is parallel in direction to the player's direction at the player's position forms the forward/backward rotation. The great circle perpindicular to this forms the left/right rotation. The forward/backward great circle probably coudl be corresponded pretty well to longitude. Both are great circles.

Latitude is not built from great circles. So I don't think an easy correspondance exists.

I dunno, the whole thing just stumps me.

Darwinbots - Artificial life simulation

###
#8
Members - Reputation: **1002**

Posted 13 March 2007 - 04:46 AM

Spherical coodinates have a base consisting of three unit vectors, given by

EDIT:~~In case it was unclear, for θ project on ~~

Or even better after giving it some thought perhaps the best way would be to:

Where

v

v

v

Where

[Edited by - Omid Ghavami on March 13, 2007 11:46:55 AM]

**e**_{r}= (sin(θ)cos(φ), sin(θ)sin(φ), cos(θ))**e**_{θ}= (cos(θ)cos(φ), cos(θ)sin(φ), -sin(θ))**e**_{φ}= (-sin(φ), cos(φ), 0)**v**(R,θ,φ) = R**e**_{r}+ θ**e**_{θ}+ φ**e**_{φ}EDIT:

**e**

_{θ}and for φ project on

**e**

_{φ}.

Or even better after giving it some thought perhaps the best way would be to:

**v**= v_{R}**e**_{r}+ v_{θ}**e**_{θ}+ v_{φ}**e**_{φ}Where

v

_{R}= dR/dtv

_{θ}= R * dθ/dtv

_{φ}= R * dφ/dt * sin(θ)Where

**v**is known in cartesian coordinates, the base vectors are known for the current position, since θ and φ are known for the current position. So you get three equations with two unknown, namely dθ/dt and dφ/dt, since you already know dR/dt = 0. Solving that will give you the change in θ and φ.[Edited by - Omid Ghavami on March 13, 2007 11:46:55 AM]

Best regards, Omid

###
#9
Members - Reputation: **501**

Posted 13 March 2007 - 05:19 AM

That looks like a solution! I'll give it a try and see waht I get. In the mean time, where did the base vectors come from? I've never seen them before, and I've been working with sphericeal coordiantes casually for a while, not to mention having covered them in calculus.

Darwinbots - Artificial life simulation

###
#10
Members - Reputation: **1002**

Posted 13 March 2007 - 05:46 AM

First of all there are different conventions for θ and φ, so don't take all the equation literary. I'm using the convention that θ is measured from

The base unit vectors are then defined so that:

Note that these base vectors are only valid for the state, they will change change as soon as

It won't however remain that simple when we take the time derivative, since

We now have an expression for the time derivative of the position vector, and we also know the numerical values for the components of the velocity in cartesian coordinates. We also know the spherical coordinate base vectors in cartesian coordinates, so we get three equations, one for each cartesian component. There will be three unknown, these are dR/dt, dθ/dt, dφ/dt. Three equations, three unknowns, sounds promising. We also happen to know that dR/dt = 0, so we only need to consider 2 of the equations.

Solving this will give us what we sought.

**R**to the z-axis, whilst φ is measured from the projection of**R**in the x-y plane to the x-axis.The base unit vectors are then defined so that:

**e**_{R}is in the direction in which movement would increase R but not alter θ and φ.**e**_{θ}is in the direction in which movement would increase θ but not alter R and φ.**e**_{φ}is in the direction in which movement would increase φ but not alter R and θ.Note that these base vectors are only valid for the state, they will change change as soon as

**R**changes. Now since**e**_{R}points in the direction of our point, the position of a given point is entirely determined by**R**= R**e**_{R}.It won't however remain that simple when we take the time derivative, since

**e**_{R}changes with time. Taking the time derivate we will reach the presented equation for the velocity**v**. The derivation is pretty straight forward but it's difficult to type it in here since there is no support for math expressions, so I won't do that.We now have an expression for the time derivative of the position vector, and we also know the numerical values for the components of the velocity in cartesian coordinates. We also know the spherical coordinate base vectors in cartesian coordinates, so we get three equations, one for each cartesian component. There will be three unknown, these are dR/dt, dθ/dt, dφ/dt. Three equations, three unknowns, sounds promising. We also happen to know that dR/dt = 0, so we only need to consider 2 of the equations.

Solving this will give us what we sought.

Best regards, Omid

###
#11
Members - Reputation: **1002**

Posted 13 March 2007 - 06:00 AM

Quote:

Original post by Numsgil

That looks like a solution! I'll give it a try and see waht I get. In the mean time, where did the base vectors come from? I've never seen them before, and I've been working with sphericeal coordiantes casually for a while, not to mention having covered them in calculus.

Any orthogonal curvilinear coordinate system has a base. You can find the basis for a curvilinear coordinate system by taking the derivative of a vector in cartesian coordinates in terms of the curvilinear coordinate components with respect to each of the components. And then normalizing.

For example in the case of spherical coordinates you have:

vector

**x**given by

x

_{1}= r * sin(a) * cos(b)

x

_{2}= r * sin(a) * sin(b)

x

_{3}= r * cos(a)

e

_{r}= d

**x**/dr / h

_{r}= [sin(a) * cos(b), sin(a) * sin(b), cos(a)] / h

_{r}

h

_{r}= | [sin(a) * cos(b), sin(a) * sin(b), cos(a)] | = 1

e

_{r}= [sin(a) * cos(b), sin(a) * sin(b), cos(a)]

e

_{a}= d

**x**/da / h

_{a}= [r * cos(a) * cos(b), r * cos(a) * sin(b), - r * sin(a)] / h

_{a}

h

_{a}= |[r * cos(a) * cos(b), r * cos(a) * sin(b), - r * sin(a)]| = r

e

_{a}= [cos(a) * cos(b), cos(a) * sin(b), - sin(a)]

e

_{b}= d

**x**/db / h

_{b}= [-r * sin(a) * sin(b), r * sin(a) * cos(b), 0] / h

_{b}

h

_{b}= |[-r * sin(a) * sin(b), r * sin(a) * cos(b), 0]| = r * sin(a)

e

_{b}= [-sin(b), cos(b), 0]

Best regards, Omid