• Create Account

Banner advertising on our site currently available from just \$5!

# Converting a rotation to spherical coordinates

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1Numsgil  Members   -  Reputation: 501

Like
0Likes
Like

Posted 11 March 2007 - 04:13 PM

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?
Artificial life simulation

### #2Numsgil  Members   -  Reputation: 501

Like
0Likes
Like

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.
Artificial life simulation

### #3Omid Ghavami  Members   -  Reputation: 1002

Like
0Likes
Like

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

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

### #4Numsgil  Members   -  Reputation: 501

Like
0Likes
Like

Posted 13 March 2007 - 03:08 AM

Quote:
 Original post by Omid GhavamiThen project w onto your axes to determine the contribution around the axes of interest.

Care to elaborate?
Artificial life simulation

### #5Omid Ghavami  Members   -  Reputation: 1002

Like
0Likes
Like

Posted 13 March 2007 - 03:47 AM

Quote:
Original post by Numsgil
Quote:
 Original post by Omid GhavamiThen project w onto 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

### #6Omid Ghavami  Members   -  Reputation: 1002

Like
0Likes
Like

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.

   % 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

### #7Numsgil  Members   -  Reputation: 501

Like
0Likes
Like

Posted 13 March 2007 - 04:33 AM

It's not the math for the projection that's throwing me, it's 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.
Artificial life simulation

### #8Omid Ghavami  Members   -  Reputation: 1002

Like
0Likes
Like

Posted 13 March 2007 - 04:46 AM

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

er = (sin(θ)cos(φ), sin(θ)sin(φ), cos(θ))
eθ = (cos(θ)cos(φ), cos(θ)sin(φ), -sin(θ))
eφ = (-sin(φ), cos(φ), 0)

v(R,θ,φ) = Rer + θeθ + φeφ

EDIT: In case it was unclear, for θ project on eθ and for φ project on eφ.

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

v = vRer + vθeθ + vφeφ

Where
vR = dR/dt
vθ = R * dθ/dt
vφ = 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

### #9Numsgil  Members   -  Reputation: 501

Like
0Likes
Like

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.
Artificial life simulation

### #10Omid Ghavami  Members   -  Reputation: 1002

Like
0Likes
Like

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 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:
eR 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 eR points in the direction of our point, the position of a given point is entirely determined by R = R eR.
It won't however remain that simple when we take the time derivative, since eR 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

### #11Omid Ghavami  Members   -  Reputation: 1002

Like
0Likes
Like

Posted 13 March 2007 - 06:00 AM

Quote:
 Original post by NumsgilThat 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
x1 = r * sin(a) * cos(b)
x2 = r * sin(a) * sin(b)
x3 = r * cos(a)

er = dx/dr / hr = [sin(a) * cos(b), sin(a) * sin(b), cos(a)] / hr
hr = | [sin(a) * cos(b), sin(a) * sin(b), cos(a)] | = 1

er = [sin(a) * cos(b), sin(a) * sin(b), cos(a)]

ea = dx/da / ha = [r * cos(a) * cos(b), r * cos(a) * sin(b), - r * sin(a)] / ha

ha = |[r * cos(a) * cos(b), r * cos(a) * sin(b), - r * sin(a)]| = r

ea = [cos(a) * cos(b), cos(a) * sin(b), - sin(a)]

eb = dx/db / hb = [-r * sin(a) * sin(b), r * sin(a) * cos(b), 0] / hb

hb = |[-r * sin(a) * sin(b), r * sin(a) * cos(b), 0]| = r * sin(a)

eb = [-sin(b), cos(b), 0]
Best regards, Omid

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS