| | } |
| | |
| | - altitudeReached(currentAltitude, currentSpeed) { |
| | - const G = 6.67384e-11; |
| | - const R0 = 6378137.0; |
| | - const M = 5.97219e24; |
| | - const mu = G * M; |
| | + /** |
| | + * Determines the rocket's current altitude. |
| | + */ |
| | + altitudeReached() { |
| | + const mu = this.planet.standardGravity(); |
| | + const r0 = this.planet.radius(this.latitude); |
| | + const r1 = r0 + this.altitude; |
| | + const r2 = mu / (-0.5 * this.vVelocity ** 2 + mu / r1); |
| | |
| | - const r1 = R0 + currentAltitude; |
| | - const r2 = mu / (-0.5 * currentSpeed ** 2 + mu / r1); |
| | - return r2 - R0; |
| | + return r2 - r0; |
| | } |
| | |
| | /** |
| | - * Checks if the rocket is still flying, i.e., if it has fuel and has not |
| | - * reached the target altitude. |
| | + * Checks if the rocket is still flying, i.e., if it has fuel, has not |
| | + * reached the target altitude, and hasn't crashed. |
| | * |
| | * @returns {boolean} True if the rocket is flying. |
 |
| | vThrust = -drag[1]; |
| | |
| | - const reached = this.altitudeReached(this.altitude, this.vVelocity); |
| | + const reached = this.altitudeReached(); |
| | |
| | // Increase vertical thrust until orbital altitude is reached. |