Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/autonoma.ca.git
calculators/rocket/payload/Earth.js
}
+ standardGravity() {
+ return Earth.STANDARD_GRAVITY;
+ }
+
rotationalSpeed(latitude, altitude) {
const radialLatitude = this.radius(latitude);
calculators/rocket/payload/Rocket.js
}
- 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.

Reuses planetary constants

Author djarvis <email>
Date 2024-12-18 21:31:32 GMT-0800
Commit 0d69a9d4acee2215037b2b38c84302b65a6c0561
Parent d9ffc2c
Delta 16 lines added, 11 lines removed, 5-line increase