HarvesteR
Member
- Joined
- Apr 22, 2008
- Messages
- 386
- Reaction score
- 15
- Points
- 18
Hello once again!
My last endeavour at predicting an orbital trajectory proved to be way over my head... so I'm going by a simpler approach...
I've decided to step ahead of the simulation, and predict the next position over a few iterations, in the hope that this way I'll get to see something that looks at least remotely similar to Orbiter's Orbit MFD.
So, this method seems to work better than the last, but there is a problem...
My orbit prediction seems to be slightly off, so at the end of 256 iterations, that tiny error amounts to a major inaccuracy... see here:
As you can see, the predicted trajectory is spiralling down... obviously this is not what actually happens if you play out the orbit... gradually, as the ship advances, the error margin for any particular point lessens (as it takes less prediction iterations to get there)
So, my theory about what's wrong here is that I'm moving my position forward along it's velocity vector, and grabbing the gravitational vector for the predicted position... then I add this new gravity vector into the last calculated velocity, and move the last known position along the new velocity...
the cause is the gravitational sampling... It's getting an outdated velocity, so the acceleration is always one frame late... the problem is that to calculate the correct gravitational pull, I'd have to add the current velocity into the last known position, which is impossible since to know the current velocity, I have to know the current gravitation...
Here's some code to help understand the matter:
The ship's initial position comes from the static FlightState properties... then I loop forward in advance of the simulation.
Currently there are no other forces acting on the ship... just gravity (as long as the engines are off... which they are).. there is no atmospheric drag yet, and the planet is perfectly spherical
The Gravitation.getGeeForceAtPosition function returns the gravity vector at the sampled position... this position is where the problem is at.
The points array is just the list of known positions for the plot (it's declared somewhere else and pretty much irrelevant to the matter)
Any help right now would be immensely appreciated :thumbup:
Cheers
My last endeavour at predicting an orbital trajectory proved to be way over my head... so I'm going by a simpler approach...
I've decided to step ahead of the simulation, and predict the next position over a few iterations, in the hope that this way I'll get to see something that looks at least remotely similar to Orbiter's Orbit MFD.
So, this method seems to work better than the last, but there is a problem...
My orbit prediction seems to be slightly off, so at the end of 256 iterations, that tiny error amounts to a major inaccuracy... see here:
As you can see, the predicted trajectory is spiralling down... obviously this is not what actually happens if you play out the orbit... gradually, as the ship advances, the error margin for any particular point lessens (as it takes less prediction iterations to get there)
So, my theory about what's wrong here is that I'm moving my position forward along it's velocity vector, and grabbing the gravitational vector for the predicted position... then I add this new gravity vector into the last calculated velocity, and move the last known position along the new velocity...
the cause is the gravitational sampling... It's getting an outdated velocity, so the acceleration is always one frame late... the problem is that to calculate the correct gravitational pull, I'd have to add the current velocity into the last known position, which is impossible since to know the current velocity, I have to know the current gravitation...
Here's some code to help understand the matter:
Code:
Vector3 pos = FlightState.position;
Vector3 vel = FlightState.velocity;
Vector3 lastPos = pos;
Vector3 lastVel = vel;
for (int i = 0; i < 256; i++)
{
Vector3 gravity = Gravitation.getGeeForceAtPosition(lastPos + lastVel);
Vector3 currVel = lastVel + gravity;
Vector3 currPos = lastPos + currVel;
points[i] = currPos;
lastPos = currPos;
lastVel = currVel;
}
The ship's initial position comes from the static FlightState properties... then I loop forward in advance of the simulation.
Currently there are no other forces acting on the ship... just gravity (as long as the engines are off... which they are).. there is no atmospheric drag yet, and the planet is perfectly spherical
The Gravitation.getGeeForceAtPosition function returns the gravity vector at the sampled position... this position is where the problem is at.
The points array is just the list of known positions for the plot (it's declared somewhere else and pretty much irrelevant to the matter)
Any help right now would be immensely appreciated :thumbup:
Cheers
Last edited: