| | +function LaunchResult(orbital, horizontal, target, deltaV, deltaVRocket, rocketDrag, mfr, hVelocity, vVelocity) { |
| | + this.orbital = orbital; |
| | + this.horizontal = horizontal; |
| | + this.target = target; |
| | + this.deltaV = deltaV; |
| | + this.deltaVRocket = deltaVRocket; |
| | + this.rocketDrag = rocketDrag; |
| | + this.mfr = mfr; |
| | + this.hVelocity = hVelocity; |
| | + this.vVelocity = vVelocity; |
| | +} |
| | + |
| | +function DragLog(rho, hVelocityNet, vVelocity, totalSpeed, ballisticCoefficient, magnitude, forceRatio) { |
| | + this.rho = rho; |
| | + this.hVelocityNet = hVelocityNet; |
| | + this.vVelocity = vVelocity; |
| | + this.totalSpeed = totalSpeed; |
| | + this.ballisticCoefficient = ballisticCoefficient; |
| | + this.magnitude = magnitude; |
| | + this.forceRatio = forceRatio; |
| | +} |
| | + |
| | +function FlightLog(time, thrust, altitude, hVelocity, vVelocity, dragForce, hAcceleration, vAcceleration, mass, massFlowRate) { |
| | + this.time = time; |
| | + this.thrust = thrust; |
| | + this.altitude = altitude; |
| | + this.hVelocity = hVelocity; |
| | + this.vVelocity = vVelocity; |
| | + this.dragForce = dragForce; |
| | + this.hAcceleration = hAcceleration; |
| | + this.vAcceleration = vAcceleration; |
| | + this.mass = mass; |
| | + this.massFlowRate = massFlowRate; |
| | +} |
| | + |
| | +function RecordLog(time, altitude, hVelocity, percentSpeed, mass, magnitude) { |
| | + this.time = time; |
| | + this.altitude = altitude; |
| | + this.hVelocity = hVelocity; |
| | + this.percentSpeed = percentSpeed; |
| | + this.mass = mass; |
| | + this.magnitude = magnitude; |
| | +} |
| | + |
| | class Rocket { |
| | constructor(wet, payload, diameter, dragCoefficient, specificImpulse) { |
 |
| | this.totalThrust = 0.0; |
| | this.targetAltitude = 0.0; |
| | + this.massFlowRate = 0.0; |
| | |
| | const crossSectionArea = Math.PI * this.radius ** 2; |
| | this.ballisticCoefficient = dragCoefficient * crossSectionArea; |
| | |
| | this.flightRecorder = false; |
| | this.launched = false; |
| | this.relocated = false; |
| | this.world = false; |
| | |
| | - this.massFlowRate = 5.0; |
| | + this.launchResults = []; |
| | + this.flightLogs = []; |
| | + this.recordLogs = []; |
| | + this.dragLogs = []; |
| | } |
| | |
 |
| | |
| | this.hVelocity = hVelocity + this.rotationalSpeed; |
| | + console.log("ROTATIONAL SPEED: " + this.rotationalSpeed); |
| | this.vVelocity = vVelocity; |
| | |
 |
| | const vRocket = this.vExhaust * Math.log(this.wet / this.targetMass); |
| | |
| | - console.info(`orbital and horizontal = ${vOrb} ${this.hVelocity}`); |
| | - console.info(`dry + payload = ${this.targetMass}`); |
| | - console.info(`Δv = ${vReq}; Δv rocket = ${vRocket}`); |
| | - console.info(`mass flow rate = ${this.massFlowRate}`); |
| | - console.info(`drag force = ${dragForce}`); |
| | - console.info(`hVelocity = ${hVelocity}`); |
| | - console.info(`vVelocity = ${vVelocity}`); |
| | + const result = new LaunchResult(vOrb, this.hVelocity, this.targetMass, vReq, vRocket, dragForce, this.massFlowRate, this.hVelocity, this.vVelocity); |
| | + this.launchResults.push(result); |
| | } |
| | |
 |
| | const forceRatio = [-hVelocityNet / totalSpeed, -this.vVelocity / totalSpeed]; |
| | |
| | - console.info(`rho = ${rho}`); |
| | - console.info(`hV (net) = ${hVelocityNet}`); |
| | - console.info(`vV = ${this.vVelocity}`); |
| | - console.info(`totalSpeed = ${totalSpeed}`); |
| | - console.info(`bC = ${this.ballisticCoefficient}`); |
| | - console.info(`magnitude = ${magnitude}`); |
| | - console.info(`ratio = [${forceRatio}]`); |
| | + const log = new DragLog(rho, hVelocityNet, this.vVelocity, totalSpeed, this.ballisticCoefficient, magnitude, forceRatio); |
| | + this.dragLogs.push(log); |
| | |
| | return [forceRatio[0] * magnitude, forceRatio[1] * magnitude]; |
 |
| | |
| | this.hAcceleration = dragForce[0] / this.wet + hThrust / this.wet; |
| | - this.vAcceleration = dragForce[1] / this.wet + this.planet.gravity(this.latitude, this.altitude) + vThrust / this.wet; |
| | + this.vAcceleration = dragForce[1] / this.wet - this.planet.gravity(this.latitude, this.altitude) + vThrust / this.wet; |
| | |
| | // Records the initial values and all subsequent deltas. |
 |
| | |
| | this.wet -= this.massFlowRate * time; |
| | - |
| | - console.log(`Time: ${time}, Altitude: ${this.altitude}, hVelocity: ${this.hVelocity}, vVelocity: ${this.vVelocity}`); |
| | - console.log(`Drag: ${dragForce}, hAcc: ${this.hAcceleration}, vAcc: ${this.vAcceleration}, Mass: ${this.wet}, Mass Flow Rate: ${this.massFlowRate}`); |
| | |
| | if (this.hVelocity < this.targetVelocity) { |
| | - const accelerationMagnitude = Math.sqrt( |
| | + const magnitude = Math.sqrt( |
| | this.hAcceleration ** 2 + this.vAcceleration ** 2 |
| | - ); |
| | + ) / 9.8; |
| | |
| | - if (accelerationMagnitude > this.maxAcceleration && |
| | + console.log(magnitude); |
| | + |
| | + if (magnitude > this.maxAcceleration && |
| | this.vExhaust * this.massFlowRate * 0.98 > absDragForce) { |
| | this.massFlowRate *= 0.99; |
 |
| | this.massFlowRate = 0.0; |
| | } |
| | + |
| | + const log = new FlightLog(time, this.totalThrust, this.altitude, this.hVelocity, this.vVelocity, dragForce, this.hAcceleration, this.vAcceleration, this.wet, this.massFlowRate); |
| | + this.flightLogs.push(log); |
| | + } |
| | + |
| | + stop() { |
| | + console.table(this.launchResults); |
| | + console.table(this.dragLogs); |
| | + console.table(this.flightLogs); |
| | + console.table(this.recordLogs); |
| | } |
| | |
 |
| | const percentSpeed = this.hVelocity / this.targetVelocity * 100.0; |
| | |
| | - console.info('time, alt, hVel :', |
| | - time, |
| | - this.altitude, |
| | - this.hVelocity, percentSpeed, this.wet, magnitude) |
| | + const recordLog = new RecordLog(time, this.altitude, this.hVelocity, percentSpeed, this.wet, magnitude); |
| | + this.recordLogs.push(recordLog); |
| | } |
| | } |