From ac2339b8b44ae0325a689b635a510144a519e86c Mon Sep 17 00:00:00 2001 From: Joe Pfeiffer Date: Tue, 21 Aug 2018 17:29:07 -0600 Subject: [PATCH] Fix Average Thrust Calculation (fixes issue #441) Remove test for short time interval before first data point in thrust curve. Comment said it was for numerical stability; multiplying by a small number and then adding doesn't introduce any instabilities I'm aware of in this code. Add parentheses to clarify that values are being multiplied by time intervals, not divided. --- .../net/sf/openrocket/motor/ThrustCurveMotor.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java index ac4b37a6b..3cf858a9c 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java @@ -321,23 +321,20 @@ public class ThrustCurveMotor implements Motor, Comparable, Se // portion from startTime through time[timeIndex] double avgImpulse = 0.0; - // For numeric stability. - if( time[timeIndex+1] - startTime > 0.001 ) { - avgImpulse = (MathUtil.map(startTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]) + thrust[timeIndex+1]) - / 2.0 * (time[timeIndex+1] - startTime); - } + avgImpulse = ((MathUtil.map(startTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]) + thrust[timeIndex+1]) + / 2.0) * (time[timeIndex+1] - startTime); // Now add the whole steps; timeIndex++; - while( timeIndex < time.length -1 && endTime >= time[timeIndex+1] ) { - avgImpulse += (thrust[timeIndex] + thrust[timeIndex+1]) / 2.0 * (time[timeIndex+1]-time[timeIndex]); + while ( timeIndex < time.length -1 && endTime >= time[timeIndex+1] ) { + avgImpulse += ((thrust[timeIndex] + thrust[timeIndex+1]) / 2.0) * (time[timeIndex+1]-time[timeIndex]); timeIndex++; } // Now add the bit after the last time index if ( timeIndex < time.length -1 ) { double endInstImpulse = MathUtil.map( endTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]); - avgImpulse += (thrust[timeIndex] + endInstImpulse) / 2.0 * (endTime - time[timeIndex]); + avgImpulse += ((thrust[timeIndex] + endInstImpulse) / 2.0) * (endTime - time[timeIndex]); } return avgImpulse / (endTime - startTime);