A specific setup problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

A specific setup problem

Postby misho » Sat Dec 24, 2016 4:17 am

Hi everyone,

I am working on a spaceflight simulator. I am using existing visual platform, and have implemented Newton for spaceflight dynamics. So far, more or less, everything works. I have bodies in orbit, behaving like they should, and I can attach them to one another using a CustomHinge to create a rigid link (docked spaceship) between the bodies. The visual system I have renders the whole planet Earth and, using double precision versions of the libraries, I am able to model bodies in orbit around the Earth.

The problem is, the visual system has no provision for Earth rotation... Therefore, my bodies always track over the same trajectory on the surface. In real life, the Earth rotates and the bodies in orbit always track ahead (eastwards) by a certain amount (22.3 degrees longitude in the case of ISS). that's why the orbital paths look like sinusoidal curves horizontally (longitudinally) separated by a certain amount.

Since there is no provision to rotate the Earth, I have tried to solve this problem by introducing a small incremental rotation of all my objects in orbit, around the z-axis, (axis that in my coordinate system connects the Earth poles) opposite to the rotation of Earth, which would have the net effect of Earth rotating . This works fine for bodies that are not attached to each other or anything, but as soon as I attach 2 bodies, an instability occurs, and they start to wildly spin and rotate around each other. I am guessing that is because the bodies are now constrained to each other, and I am trying to apply positional changes (due to the rotation) separately to each one of them.

I know I shouldn't be applying positional changes directly to bodies (I should be applying only forces to the bodies and let solver take care of the positions and velocities) however, I am unsure how else to achieve the effect I need to get the Earth rotation working.

I have considered also calculating and adding a velocity vector that compensates for the Earth rotation, but that would definitely throw off orbital speeds (on equator, Earth spins at 1674 km/h).

Any idea on any better ways of accomplishing this? Thanks in advance!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: A specific setup problem

Postby Julio Jerez » Sat Dec 24, 2016 8:50 am

let me see if I understand.
basically you have two bodies joint by a joint. And you want to rotate them.
your approached is that now applying a direct rotation modifying the matrices.
does that describe the problem?

some question:
are you connecting them with a joint acting as a fix joint? if this is the case is a simpler problem.
what center are you spinning them around? Are you getting a common origin or are you spinning each then around their own center?
can you draw a sketch?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A specific setup problem

Postby Shaderman » Sat Dec 24, 2016 11:55 am

I probably got it wrong, but if the center of your universe is the earth, probably the newton world can be rotated and thus everything in your universe.
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: A specific setup problem

Postby misho » Sat Dec 24, 2016 1:53 pm

Hi!

Thanks for responding! Here is the set-up:

The centre of the "universe" is Earth. Centre of the coordinate system is Earth centre.
The bodies are rotating (orbiting) around the Earth at ~6700km altitude (Earth radius + orbital altitude)
In order to "fake" Earth rotation, I rotate EACH body orbiting by a small amount, AFTER Newton calculates their positions.
The rotation is around "universe" Z-axis (axis that goes through the poles), NOT around body's local axis.
Here is a good illustration of what I am doing (this is the case for International Space Station):

https://www.youtube.com/watch?v=2Rc3rh9o-QE

A small amount of rotation I introduce results in a proper "ground track": A sinusoidal-shaped path when projected on Earth's surface:

http://hakenberg.de/numerics/orbits/iss_track.jpg

You can see how the "ground track" moves from east to west as each progressive orbit is completed. That is due to Earth's rotation. Satellite orbits around Earth in a "fixed" loop with respect to Orbit around Sun, while the Earth rotates... in other words, the satellite does not rotate with Earth around orbit (when they do, they are called geosynchronous satellites) .

My approach works while the objects are not linked to anything... however, as soon as I link objects, they start to wildly spin around each other. I am pretty sure that is because I am introducing "shifts" in their positions AFTER Newton's calculations. Please note that I am doing this while the objects are moving at orbital speeds, around 7000 m/s, so I am guessing that there is an imprecise timing somewhere, and by the time I introduce a link, the objects don't have synced speeds and start to behave as described.

I was wondering if there was a better way of accomplishing what i'm trying to do...

BTW, I'm doing this rotation properly, in NewtonBodySetTransformCallback.

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

Re: A specific setup problem

Postby misho » Sat Dec 24, 2016 2:01 pm

Shaderman wrote:I probably got it wrong, but if the center of your universe is the earth, probably the newton world can be rotated and thus everything in your universe.


Yes, that is correct, I am trying to rotate the whole newton world around Z axis:

I am:

using a QueryPerformanceFrequency timer to get the number of microseconds since last loop
Using that time to get the fraction of the angle that Earth rotated (full Earth rotation is 360 degrees per day, or 360/(24*60*60) per second)
Rotating every single newton body by that small fraction of an angle around the z (pole) axis, thus "relatively" rotating earth.

I am guessing that, when I apply those rotations to linked objects separately, that results in slightly different values per-object, resulting in them spinning around each other.

I hope I'm making this clear :lol:
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: A specific setup problem

Postby JoeJ » Sat Dec 24, 2016 6:17 pm

It sounds like you are only aplying rotation to newton bodies? That would be very wrong.
You also need to rotate their positions arund the z axis.
If you do this correctly, relative transform between two bodies does not change and the joints should keep working.

Edit: I forgot about velocity and all the other engine internal physical properties also in the joints.
So Julios suggestion below seems the only way.
Last edited by JoeJ on Sun Dec 25, 2016 7:44 am, edited 1 time in total.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: A specific setup problem

Postby Julio Jerez » Sat Dec 24, 2016 7:32 pm

Oh I see you try to rotate the entire world.
if that is the case you are experiencing the Coriolis effect.
This is the acceleration that an inertial body experience when the body moves on a rotational frame of reference.

newton was no designed to handle that by you can apply a work around by adding the forces by applying the forces as external Centripetal and Coriolis forces generated by the medium that the body is in the force and torque callback.

the general expression for the forces on an non ionetial frame is.
coriolisforces.png
coriolisforces.png (6.89 KiB) Viewed 11374 times

Code: Select all
F = m * a = fext - m * (2 * crossProduct (w, v)) - crossProduct (w, crosProduct (w, rb)) - crossProduct (alpha, r)) 


m = mass of the body in orbit
w = planet angular velocity
v = linear velocity of body in orbit.
rb = distance for body in orbit to the center of the planet
alpha = angular acceleration of the planet
fext = the forces that proper the ship

I assume the planet is not acceleration, so you can ignore the last term in the general expression

so in you force call back you modifies to calculation these two expressions.

coriolistAcceleration = -2 * crossProduct (w, v)
centripetalAcceleration = - crossProduct (w, crosProduct (w, rb))
them the total force is:

F = m * a = fext + m * (coriolistAcceleration + centripetalAcceleration);

here is a good Wikipedia site that can help explain why these forces come about.
https://en.wikipedia.org/wiki/Coriolis_force
look the segment Components acceleration.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A specific setup problem

Postby misho » Tue Dec 27, 2016 5:21 am

Hi Julio!

Thanks for the suggestion/explanation. I've looked at this equation for a few days now, and It raises more questions than answers, at least to me... For example, to calculate the force that acts on a body in orbit (centripetal force) that has no external forces acted on it (no external thrust), I use a classic F=GM/(r^2), where GM is a universal gravitational constant x Mass of earth, and r is the distance to the centre of Earth. This formula gives me an exact result (That is, my bodies in orbit behave like the real world spacecraft, same orbital period down to the second, etc.)

In your formula for centripetal force, I don't see a GM factor (which should be there as it varies from a planet to planet), plus, I don't see how w (planet angular velocity) is a factor - why would an orbiting body care if the body which it is orbiting around spins? The spin of the Earth is only factored in achieving an orbital speed: A rocket launched from the equator benefits from this launch position because it already is travelling at a speed of around 1674km/h at the moment of launch, so it can spend less fuel to get to orbital speed and therefore lift larger cargo. Most, if not all rockets are launched eastwards because of this fact. In fact, there is a commercial launch company (SeaLaunch) which launches from equatorial positions off the sea platform just because of this benefit.

In any case, up in the orbit, the satellite does not care if the body under it spins or not. After all, the same formula F=GM/(r^2) can be applied for orbits around moon (with GM specific for moon), and moon's w is 30 times slower than Earth's (moon's complete revolution takes 1 month). There is certainly no w factored in any orbital calculations - except, as I mentioned, during the launch itself.
Last edited by misho on Tue Dec 27, 2016 5:40 am, edited 2 times in total.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: A specific setup problem

Postby misho » Tue Dec 27, 2016 5:37 am

JoeJ wrote:It sounds like you are only aplying rotation to newton bodies? That would be very wrong.
You also need to rotate their positions around the z axis.
If you do this correctly, relative transform between two bodies does not change and the joints should keep working.

Edit: I forgot about velocity and all the other engine internal physical properties also in the joints.
So Julios suggestion below seems the only way.


Hi! Actually - no, I am not rotating bodies around their local axis. I am rotating them by a small amount every frame around the "world" z-axis. That small rotation changes their position but not their rotation (attitude). Or, to be more precise, their attitude is fixed to the stars. I get the desired result if the bodies aren't linked to anything, but as soon I link them, they go "berserk" :lol:
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: A specific setup problem

Postby Julio Jerez » Tue Dec 27, 2016 6:57 am

the formula GM/r2 is part of Fext
this equation comes from the derivation of the Langragian mechanic and uses the kinetic and potential energy of a entire system of particles in motion. In is more general that Newton Law of Graviation. in fact Newton universal gravitation can also be derived the same way, if we add the expression of the potential energy of the two bodies in - GM/r, but you are adding that already as GM/r2, so I only showed you the Coriolis which is what you miss.
Code: Select all
coriolistForce = - M * (2 * crossProduct (w, v) + crossProduct (w, crosProduct (w, rb))) 


this force generate an force perpendicular to the angular velocity of the medium and tangent to the trajectory. Believe me that formula is right.
This is the same force that makes tornados and hurricanes spin when the low pressure center * air particles toward a center of pressure, the Coriolis force give the a circular motion around the center and a repealing force, however the centripetal term cancel the repealing force and the particles goes to spiral trajectory.
This is the force that rockets also use to save fuel, and it is the force that you feel when you try to walk of a merry go round at a carnival.

you just add that force to your body in orbit and you will see if will fix it.

notice the w is the angular velocity of the planet and v is the velocity of your space ship. this fore is zero if either w, v zero or cross(v, w) is zero, while GM/r2 is never.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A specific setup problem

Postby misho » Fri Dec 30, 2016 3:12 am

Ok, thanks Julio, I will implement it.

However, the more I think about this, the more I see I have a larger problem. The problem I described applies to bodies that are already in orbit. The larger picture is this:

I have a "fixed" world, that has to be rotating.
The rocket launching from equator already has a speed of 1670 km/h, because of Earth's rotation. The rocket launched towards East has a benefit of this speed already, so it can achieve orbital speed a little easier.

To simulate this, I have to give ALL my bodies an initial omega around a global Z axis, as if all bodies are rotating along with Earth.

However, in the case of a rocket that is on a launch pad and ready to be launched, I have to "roll back" this omega by an equal and opposite amount so that it appears steady in relation to the ground.

Once in proper orbit, this equal and opposite omega will shift my bodies a bit backwards, appearing as if the earth is rotating underneath.

Am I on the right track? Is this the right approach? Any insight would be helpful...

BTW, if you guys wanna follow what I'm doing, I have a FB page where I post my progress:

https://www.facebook.com/TerraBuilder/

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

Re: A specific setup problem

Postby Julio Jerez » Fri Dec 30, 2016 9:39 am

misho wrote:I have a "fixed" world, that has to be rotating.
The rocket launching from equator already has a speed of 1670 km/h, because of Earth's rotation. The rocket launched towards East has a benefit of this speed already, so it can achieve orbital speed a little easier.

To simulate this, I have to give ALL my bodies an initial omega around a global Z axis, as if all bodies are rotating along with Earth.

However, in the case of a rocket that is on a launch pad and ready to be launched, I have to "roll back" this omega by an equal and opposite amount so that it appears steady in relation to the ground.

Once in proper orbit, this equal and opposite omega will shift my bodies a bit backwards, appearing as if the earth is rotating underneath.

Am I on the right track? Misho

noo you are on the wrong track, 8)
you could no call that a simulation, if you when that far, you should strike for getting everything as emerging physics behavior out of the simulation.

A vehicle in a launch pad will have zero linear velocity, therefore the Coriolis force is zero, no correction needed.
it is only when the vehicle has a non zero component of the linear velocity perpendicular to the angular velocity of the rotation medium that these forces take place.
like is said use that formula and all your problems will go away. is better to fix the engine problem and have good physics that hack your way around the engine.

Another things I recommend to help with stability is:
1-use the Skeleton joint when you do your docking, this joint are more robust and help to resolve the non linearity of the complex motion. see the standard joints demos.
2- use void NewtonSetNumberOfSubsteps (newtonWorld, 2); or maybe even 4
this will sub sample the simulation and given you quadric convergence

I believe those twos things alone with the formula I gave you and you will have a NASA quality simulation.

BTW your videos and images look terrific. :mrgreen:
once you get it all tuned, I can't think of a better application for the new virtual reality grasses than your.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A specific setup problem

Postby misho » Fri Dec 30, 2016 2:27 pm

Thanks Julio! It will be my pleasure to display "Built with Newton Dynamics" once I release the sim! :mrgreen:

Of course, you being the co-author of the physics engine, there's probably no one that understands its inner workings better, so I'll follow your advice implicitly.

However - I just don't understand how the east-west launch dynamics will get resolved given the equations you suggested. Here's the situation: (refer to the attached image)

In the REAL world, Earth rotates counterclockwise if viewed from above. That means that a rocket on a launch pad on the equator already has a velocity of 460 m/s eastwards. So, if I want to launch my rocket eastwards, I require a delta v of 7800 - 460 = 7340 m/s. In this case, the earth rotation helps me out, and this is how, in reality, most if not all rockets are launched.

Conversely, if I want to launch my rocket westwards, I will require to "overcome" earth rotation to achieve 7800 m/s, so my required delta v would be 7800 + 460 = 8260 m/s. Compared to eastwards launch, that's a difference of almost 1000 m/s...

However, I have a FIXED world. If a rocket launcher is on equator, a launch to Lower Earth Orbit (LEO) requires a delta v of around 7800 m/s. For me, on a fixed world, it doesn't matter if I launch east OR west - it will require the same delta v. That's not how it is in the real world.

So - how do I set up my simulation to accurately take account for this real-world situation?

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

Re: A specific setup problem

Postby JoeJ » Sat Dec 31, 2016 3:02 am

misho wrote:So - how do I set up my simulation to accurately take account for this real-world situation?


If i get it right, you just add the force F to every body all over the time, that's all.

Before launch the body to earch relative velocity v is zero, so is F.
After launch v increases, so F smoothly grows and creates the effect as if the earth would spin.
No need for any instant change at all, and also no need to touch any of the angular properties.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: A specific setup problem

Postby Julio Jerez » Sat Dec 31, 2016 2:44 pm

yes like Joe said, you just write your force an torque callback and there just like when using inertial frame where gravity is a property of the medium.
in your simulation the medium has an angular velocity, this will produce the Coriolis and centripetal acceleration that apply to every object no matter where the object is.

in you case the non inertial frame is centered at the origin of the earth, so it is as if the earth is the root of a hierarchy and all object a children.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 12 guests

cron