diff --git a/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java b/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java index f235da572..ac8496d42 100644 --- a/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java +++ b/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java @@ -273,8 +273,8 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { // Call post-listeners store.accelerationData = SimulationListenerHelper.firePostAccelerationCalculation(status, store.accelerationData); - params.a = dataStore.linearAcceleration; - params.ra = dataStore.angularAcceleration; + params.a = dataStore.accelerationData.getLinearAccelerationWC(); + params.ra = dataStore.accelerationData.getRotationalAccelerationWC(); params.v = status.getRocketVelocity(); params.rv = status.getRocketRotationVelocity(); @@ -298,7 +298,9 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { * @throws SimulationException */ private AccelerationData calculateAcceleration(SimulationStatus status, DataStore store) throws SimulationException { - + Coordinate linearAcceleration; + Coordinate angularAcceleration; + // Compute the forces affecting the rocket calculateForces(status, store); @@ -328,30 +330,30 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { store.thrustForce = calculateThrust(status, store, false); double forceZ = store.thrustForce - store.dragForce; - store.linearAcceleration = new Coordinate(-fN / store.rocketMass.getMass(), + linearAcceleration = new Coordinate(-fN / store.rocketMass.getMass(), -fSide / store.rocketMass.getMass(), forceZ / store.rocketMass.getMass()); - store.linearAcceleration = store.thetaRotation.rotateZ(store.linearAcceleration); + linearAcceleration = store.thetaRotation.rotateZ(linearAcceleration); // Convert into rocket world coordinates - store.linearAcceleration = status.getRocketOrientationQuaternion().rotate(store.linearAcceleration); + linearAcceleration = status.getRocketOrientationQuaternion().rotate(linearAcceleration); // add effect of gravity store.gravity = modelGravity(status); - store.linearAcceleration = store.linearAcceleration.sub(0, 0, store.gravity); + linearAcceleration = linearAcceleration.sub(0, 0, store.gravity); // add effect of Coriolis acceleration store.coriolisAcceleration = status.getSimulationConditions().getGeodeticComputation() .getCoriolisAcceleration(status.getRocketWorldPosition(), status.getRocketVelocity()); - store.linearAcceleration = store.linearAcceleration.add(store.coriolisAcceleration); + linearAcceleration = linearAcceleration.add(store.coriolisAcceleration); // If still on the launch rod, project acceleration onto launch rod direction and // set angular acceleration to zero. if (!status.isLaunchRodCleared()) { - store.linearAcceleration = store.launchRodDirection.multiply(store.linearAcceleration.dot(store.launchRodDirection)); - store.angularAcceleration = Coordinate.NUL; + linearAcceleration = store.launchRodDirection.multiply(linearAcceleration.dot(store.launchRodDirection)); + angularAcceleration = Coordinate.NUL; store.rollAcceleration = 0; store.lateralPitchAcceleration = 0; @@ -367,23 +369,23 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { double momZ = store.forces.getCroll() * dynP * refArea * refLength; // Compute acceleration in rocket coordinates - store.angularAcceleration = new Coordinate(momX / store.rocketMass.getLongitudinalInertia(), + angularAcceleration = new Coordinate(momX / store.rocketMass.getLongitudinalInertia(), momY / store.rocketMass.getLongitudinalInertia(), momZ / store.rocketMass.getRotationalInertia()); - store.rollAcceleration = store.angularAcceleration.z; + store.rollAcceleration = angularAcceleration.z; // TODO: LOW: This should be hypot, but does it matter? - store.lateralPitchAcceleration = MathUtil.max(Math.abs(store.angularAcceleration.x), - Math.abs(store.angularAcceleration.y)); + store.lateralPitchAcceleration = MathUtil.max(Math.abs(angularAcceleration.x), + Math.abs(angularAcceleration.y)); - store.angularAcceleration = store.thetaRotation.rotateZ(store.angularAcceleration); + angularAcceleration = store.thetaRotation.rotateZ(angularAcceleration); // Convert to world coordinates - store.angularAcceleration = status.getRocketOrientationQuaternion().rotate(store.angularAcceleration); + angularAcceleration = status.getRocketOrientationQuaternion().rotate(angularAcceleration); } - return new AccelerationData(null, null, store.linearAcceleration, store.angularAcceleration, status.getRocketOrientationQuaternion()); + return new AccelerationData(null, null, linearAcceleration, angularAcceleration, status.getRocketOrientationQuaternion()); }