Started by Mar 11 2007 04:13 PM

,
10 replies to this topic

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?

Darwinbots - Artificial life simulation

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

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.

Setup the equation

Then project

Best regards, Omid

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

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,v>u^{'}= ------v

|v|^{2}

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

Where <

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

Best regards, Omid

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|^{2}

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

Best regards, Omid

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.

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

Posted 13 March 2007 - 04:46 AM

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

**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:~~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** = v_{R}**e**_{r} + v_{θ}**e**_{θ} + v_{φ}**e**_{φ}

Where

v_{R} = 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]

EDIT:

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]

Best regards, Omid

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

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:

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

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.

Best regards, Omid

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

x

x

e

h

e

e

h

e

e

h

e

Best regards, Omid