From 5f1440e3f617d6e71eb638caf6be22f2295085dc Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Sun, 16 Oct 2022 17:04:59 -0600 Subject: [PATCH] Use absolute value of jerk in calculating time step in BasicLandingStepper() Don't let time step in BasicLandingStepper() get smaller than MIN_TIME_STEP (.001 seconds) --- .../sf/openrocket/simulation/AbstractSimulationStepper.java | 2 ++ .../src/net/sf/openrocket/simulation/BasicLandingStepper.java | 4 +++- .../net/sf/openrocket/simulation/RK4SimulationStepper.java | 3 --- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java b/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java index e247da7f4..637d5c6e3 100644 --- a/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java +++ b/core/src/net/sf/openrocket/simulation/AbstractSimulationStepper.java @@ -13,6 +13,8 @@ import net.sf.openrocket.util.Quaternion; public abstract class AbstractSimulationStepper implements SimulationStepper { + protected static final double MIN_TIME_STEP = 0.001; + /** * Compute the atmospheric conditions, allowing listeners to override. * diff --git a/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java b/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java index 78e1e00bb..ca809dcbb 100644 --- a/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java +++ b/core/src/net/sf/openrocket/simulation/BasicLandingStepper.java @@ -73,10 +73,12 @@ public class BasicLandingStepper extends AbstractSimulationStepper { double timeStep = RECOVERY_TIME_STEP; // adjust based on change in acceleration (ie jerk) - final double jerk = linearAcceleration.sub(status.getRocketAcceleration()).multiply(1.0/status.getPreviousTimeStep()).length(); + final double jerk = Math.abs(linearAcceleration.sub(status.getRocketAcceleration()).multiply(1.0/status.getPreviousTimeStep()).length()); if (jerk > MathUtil.EPSILON) { timeStep = Math.min(timeStep, 1.0/jerk); } + // but don't let it get *too* small + timeStep = Math.max(timeStep, MIN_TIME_STEP); // Perform Euler integration Coordinate newPosition = status.getRocketPosition().add(status.getRocketVelocity().multiply(timeStep)). diff --git a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java index 7786876c9..80275a52b 100644 --- a/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java +++ b/core/src/net/sf/openrocket/simulation/RK4SimulationStepper.java @@ -58,9 +58,6 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { private static final double MAX_ROLL_RATE_CHANGE = 2 * Math.PI / 180; private static final double MAX_PITCH_CHANGE = 4 * Math.PI / 180; - private static final double MIN_TIME_STEP = 0.001; - - private Random random;