Rotating a Newton Coordinate system

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Rotating a Newton Coordinate system

Postby misho » Thu Sep 26, 2019 12:10 am

Hi all!

Is there a way to have a rotating coordinate system in Newton?

A bit of a background:

I'm implementing a spaceflight simulator based on Microsoft's Flight Simulator X, which has an entire Earth modelled. The world has an accurate date/time system. However, the Earth does not rotate - Microsoft implemented a "trick" by rotating a sky sphere around Earth, so that the stars at night are in the correct positions. This isn't a problem for aircraft flying in atmosphere, because their frame of reference is Earth Coordinate system.

However, for spacecraft, when they exit atmosphere and orbit around Earth, they stop rotating with earth and assume celestial frame of reference, with Earth orbiting beneath them. That's why the ground track of the orbiting satelite never goes over the same position on earth.

I thought this would be a simple task to implement: basically, while in orbit, rotate the position vector of the body (vector from the Earth center to object position) around Earth's axis by the angle earth rotates in one simulation step, and thus make the static earth appear to rotate. However - things are much more complicated than I realized. This change of position of the object in orbit is now throwing off orbital motion calculations. It looks like a proper solution is to rotate a whole Newton World coordinate system around the Earth axis, so that the body's position won't have to be updated.

So, is there a way in Newton to have a rotating coordinate system for this purpose? Or, am I approaching this problem from the wrong angle?

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am

Re: Rotating a Newton Coordinate system

Postby Dave Gravel » Thu Sep 26, 2019 1:05 am

I'm not a expert with this but I think it can cause a lot more problems to change the newton coordinate system.
Many things is based on it if i'm not wrong.
Maybe the only way how it don't cause problem is if you have multiple newton world instances.
I don't think this is a good idea to have multiple world instances.

Normally the dynamic object coordinate is give from the gravity direction inside the applyforce callback. If the newton coordinate is change it can surely cause problem with other object not in orbit.
Or maybe it can cause problem with some joints creation too.

I'm not sure if you use real dynamic body or kinematic body, But maybe you can just use a listener.
You can maybe make something similar to the KinematicBodies demo or trigger demo ArchimedesBuoyancy.
Exemple you create a listener object list, When the object go in orbit state you add the object in the listener list.
On this way you can control the object from the PreUpdate and PostUpdate.
You can take a look about the class KinematiocListener: public dCustomListener in the newton sdk.
The object in orbit don't have to deal with mass maybe it can become a good idea to use kinematic bodies when you are in orbit state.
From the PreUpdate you can apply velocity on the body, If the object need local rotation you can apply some omega.
Exemple for generate the global rotation you can surely add the velocity with a cos value in x and a sin value in z or something similar.
In the PostUpdate you can integrate the velocity with NewtonBodyIntegrateVelocity.
The kinematic body have collision but it don't have mass, I'm not sure how you can deal with it when the object is not in orbit. Maybe you can just recreate a dynamic body or simulate the mass with the velocity.
If you use a trigger listener maybe you can use a big sphere as trigger for the earth, And when the object is outside the trigger it become in orbit state... I'm not sure, I never have test about it.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Rotating a Newton Coordinate system

Postby misho » Thu Sep 26, 2019 2:08 pm

Thanks Dave!

Ugh - this sounds very ugly and complicated. I am going to think about this a bit more. One thing that is possible is, I have the control over WHERE my visual object is, separate from Newton body. So far, I have always kept them "together": visual object is always exactly where Newton body is.

But, what if I moved visual object only? As in, what if I rotated the whole visual world (objects), not the physical world? That would not disrupt Newton, and Newton would be still calculating things correctly, but the display would be offset by the earth rotation amount...

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am

Re: Rotating a Newton Coordinate system

Postby Dave Gravel » Thu Sep 26, 2019 3:15 pm

If you don't need collision at all in orbit for sure it is more simple with the visual object only.
If you just need simple rotation you can do something similar.
Code: Select all
procedure UpdateVisualScene(ctx: PRenderContext; glstep: dFloat; glnewtime: dFloat);
var amat: TMatrix;
begin
  amat := test.GetFinalAbsoluteMatrix();
  amat.m_posit.X := (45+Sin(glnewtime*0.25)*180-45);
  amat.m_posit.Z := (45+Cos(glnewtime*0.25)*180-45);
  test.SetMatrix(amat);
end;


Or you create a matrix, You place this matrix at the earth position.
You apply the earth rotation on this matrix.
You multiply the objects with this earth matrix.
On this way you can rotate the object matrix in global from the earth matrix.
If you don't need the earth rotation just to don't apply rotation on the first matrix.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Rotating a Newton Coordinate system

Postby misho » Thu Sep 26, 2019 4:05 pm

Actually - I do need collisions in orbit - VERY important during docking :mrgreen:

However, think about it:

Collisions will work, because the other body will also be offset-rotated. The Visual objects will follow what newton body does, except they will all be rotated some number of degrees - in a sense, angular offset.

It is probably easier to think about it using linear offset: What I have now is, two newton bodies interacting (colliding), and their visual representations (IN THE SAME POSITIONS) showing the collision interaction.

Now - simply give visual objects a linear offset. They are still colliding, except some distance away from their physical bodies. :wink:

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am

Re: Rotating a Newton Coordinate system

Postby Julio Jerez » Thu Sep 26, 2019 5:13 pm

twice I trey to reply to this and twice window froze. I try to replay tonight.

but is not that complicated, to simulate a rotation frame you just need to add one extra term to the force and torque call back, to save time read the article in wikipedia
https://en.wikipedia.org/wiki/Coriolis_force

then I tell you what to do to add the Coriolis effect in teh force and torque. you nee to add some extra thong to represent the rotation frame. but si very eassy.
Julio Jerez
Moderator
Moderator
 
Posts: 10993
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Rotating a Newton Coordinate system

Postby misho » Fri Sep 27, 2019 3:18 pm

Thanks Julio - that would be great!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 552
Joined: Tue May 04, 2010 10:13 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron