Help with coordinate system conversion

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Help with coordinate system conversion

Postby misho » Tue Apr 28, 2015 2:52 pm

Hi JoeJ,

Yes, correct, I have the positions figured out - simple cartesian-to-polar conversion - and I have it working perfectly. However, the orientation is a tough(er) nut to crack.

And yes - at the first glance, the conversion is a "simple" rotation of coordinate systems, by "unwinding" the global position, first by longitude angle around the pole axis, then by latitude angle around the 0th meridian plane (Greenwitch/date-meridian). This places the spacecraft to a position as if it was on the North Pole, which aligns with the newton coordinate system.

I tried that, but it is not quite that simple. There are problems with the way heading (yaw) is oriented, also, a limitation of the pitch which I specified before.

Yes - the instability you mention is called a "gimbal lock", a well known condition that exists in aerospace engineering. Quaternions are used, among other reasons, to avoid just such a condition, and that's why I chose Newton (which uses quaternions).
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Help with coordinate system conversion

Postby JoeJ » Tue Apr 28, 2015 3:37 pm

Ok, it seems like i assumed. It also fits to the numbers from your screenshot - undefined over pole, then a 180 degree jump. The same would happen to the reference orientation: It would turn 180 degrees to keep pointing north, but because ship keeps its orientation the difference from ship to reference becomes 180.

There is a good chance it works like i described - with trial and error for the details (which axis is pitch, handness, etc...).
The Reference system north axis keeps always aligned with longitude and tangent with lattitude, so the "unwinding" for orientation should happen automatically and the "90<=0<=90" too.


EDIT: Fixed a terrible bug in the post with pseudo code
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Help with coordinate system conversion

Postby misho » Tue Apr 28, 2015 5:23 pm

That's right, and that happens to my spaceship if it orbits over the pole... it keeps the direction, then, it swings around as it passes the pole, keeping its nose towards the pole. That's because I keep feeding it fixed heading, and it sticks to it. In ship's case, obviously, it would be the compass needle that would flip, not the ship :)

I need (or rather, Newton needs) to feed it adjusted heading values with every frame, as it moves along Earth's surface (or rather, orbit which follows the surface track) and changes position, so that the nose keeps a fixed orientation relative to Earth (or stars, in this case). Same goes for other two rotations, pitch and roll.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Help with coordinate system conversion

Postby Julio Jerez » Wed Apr 29, 2015 9:02 am

few questions.
does not the cordenate system has a oriog an the center of the globe?

dos teh API you have use local cordinate system? if so the going form an intetial frame ot a rotaionl frame requires conapsation the velocity too, other wise the values win't mathc form on system to teh other

the coversion is:
say V is teh velocity in global system (that will be newton)
X is the velocity in the loca system (the plane)
R the position to teh origin

the
V = X + crossProduct (Omega, R)

this could get complicated, but I asume the API already take care of that. so ignore that for now.
I am surprice that the API does no give you cartesian cordinade ready to use. :shock:
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Help with coordinate system conversion

Postby misho » Wed Apr 29, 2015 11:00 am

Hi Julio,

This could get complicated? Uh oh - I thought it already was! :shock: :D

I am not sure if I understand why velocities would get involved. I have set up a point gravity "well" in Newton such as that the gravity vector points to the origin (in Newton) wherever in space the object is. I have a few objects in my test app (which I derived from the Newton tutorials) and, after I give them an initial velocity at setup, they happily (or "frownily" :mrgreen: ) orbit around the origin, in 3D space. I tried different orbital planes and elliptical orbits... they all seem to work perfectly.

I haven't tested this in my flight simulator (I need double precision because of the distances involved, but that's a whole other topic :lol: ), but I think that just passing positions (converted into latitude, longitude and altitude, plus, converted attitude, when I get this figured out) to the sim should do the trick. After all, the flight simulator is just a "dumb" display system.

I should note that, in the sim, I set up a simple, cartesian circle formula orbit (using angles and trig) to test my formulae for positional conversion, and it works perfectly. I have a simple orbit (I could even incline it to any angle) and everything works. I don't see why I couldn't simply switch my simple circle formula for "real" Newton positional data.

Yeah - I wish the API would have the proper Cartesian coordinate option. I suppose the authors never thought anyone in their right mind would use it as a spaceflight simulator... and since it is a true flight simulator (with a true spherical earth model), it would make sense to only offer the positional/rotational input of data in the aircraft-native coordinate reference frame.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Help with coordinate system conversion

Postby Julio Jerez » Thu Apr 30, 2015 8:00 am

Ok, I was saying if you need to read velocities.
I am not sure what it is that you are doing, but in general vehicle dynamics is no done in a Catrsial space, it is doin in a generalize cordinate system (why i ti scall that I do not know)

But basically it is the secudn law of newton expressed in teh local space of the body.
a body is on tha have intanstanews velocity and intanstaneus angular avelocity.

teh contribution on linera velocity nanich by teh contribution of anghula velocity does no do the equations of motion in alocal frame (the frame of teh vehicle)

are given by

Sum of force f1 + f2 + ... + fn = m * a + cross (w, v)

a is acceleration
w in angular velocity
and v in linear vilicity.

The method that is use to defive teh equation of motion is called Lagragian dynamics, and it is usefull because it lead to noce close form equationfor system like: Pedulum, Lateral dinamics for a vehicle, amost any thing that is relation to the physics of one body in insulation.
This system in unpractical for rigibody dynamics but for vehicles (car and airplnes)
is very usefull becuase after expantion, many of the quantities changes so litlle from the stady state values, that they can be aproximanted by linear exanpation or lookup tables.
For example side slip is almost constant, velocity is almost contanat, side velocity si almoc zero.

The point is that if your API is giving you generalized cordinates (local space values)
and you need to use velocities then you most use the compensation to convert from one space to the other.
You can just ingore this, if you are only using positions and angular orientation.

on the double, I see if I can compile the double presition when I get back.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Help with coordinate system conversion

Postby misho » Tue May 05, 2015 1:05 am

Hi Julio,

I am simulating bodies in orbit around a mass, all using Newton libraries, basing them on your tutorial examples, except I defined a gravity field as always pointing towards the centre of the of the Cartesian space. I am defining bodies with masses and Newton collision primitives just like they are defined in tutorials. Then, I simply pass the positions and angular orientations into my "display engine" (Flight Simulator) - that is all. I let Newton take care of all the physics. So - as you mentioned, I don't need to worry about velocities, just positions and angular orientations.

On another note, I am implementing coordinate system flip (right handed to left handed) - seems to be working. One question I have is - do I need to be implementing this flip operation also on all of the vertices of my objects in space? Or just positions of objects?
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Re: Help with coordinate system conversion

Postby Julio Jerez » Tue May 05, 2015 2:36 pm

misho wrote:One question I have is - do I need to be implementing this flip operation also on all of the vertices of my objects in space? Or just positions of objects?

no, only position and orientation
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Help with coordinate system conversion

Postby misho » Tue May 05, 2015 2:43 pm

Ah - great, thank you!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 675
Joined: Tue May 04, 2010 10:13 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron