SafetyMutex and rocket optimization updates
[debian/openrocket] / src / net / sf / openrocket / motor / ThrustCurveMotor.java
index ce3108dd048f35cc8e032f207eb3cd95179d97b1..a51283eaefd341c447d32c861c807b187ce0349c 100644 (file)
@@ -280,12 +280,11 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                        throw new BugException("Could not compute burn start time, maxThrust=" + maxThrust +
                                        " limit=" + thrustLimit + " thrust=" + Arrays.toString(thrust));
                }
-               if (MathUtil.equals(thrust[pos], thrust[pos + 1])) {
+               if (MathUtil.equals(thrust[pos - 1], thrust[pos])) {
                        // For safety
-                       burnStart = (time[pos] + time[pos + 1]) / 2;
+                       burnStart = (time[pos - 1] + time[pos]) / 2;
                } else {
-                       burnStart = MathUtil.map(thrustLimit, thrust[pos], thrust[pos + 1],
-                                       time[pos], time[pos + 1]);
+                       burnStart = MathUtil.map(thrustLimit, thrust[pos - 1], thrust[pos], time[pos - 1], time[pos]);
                }
                
 
@@ -319,9 +318,9 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                        double t0 = time[pos];
                        double t1 = time[pos + 1];
                        double f0 = thrust[pos];
-                       double f1 = thrust[pos];
+                       double f1 = thrust[pos + 1];
                        
-                       totalImpulse += (f0 + f1) / 2 * (t1 - t0);
+                       totalImpulse += (t1 - t0) * (f0 + f1) / 2;
                        
                        if (t0 < burnStart && t1 > burnStart) {
                                double fStart = MathUtil.map(burnStart, t0, t1, f0, f1);
@@ -394,7 +393,7 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                private Coordinate instCG;
                
                private final double unitRotationalInertia;
-               private final double unitLongitudalInertia;
+               private final double unitLongitudinalInertia;
                
                private int modID = 0;
                
@@ -407,7 +406,7 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                        instCG = cg[0];
                        stepCG = cg[0];
                        unitRotationalInertia = Inertia.filledCylinderRotational(getDiameter() / 2);
-                       unitLongitudalInertia = Inertia.filledCylinderLongitudal(getDiameter() / 2, getLength());
+                       unitLongitudinalInertia = Inertia.filledCylinderLongitudinal(getDiameter() / 2, getLength());
                }
                
                @Override
@@ -421,8 +420,8 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor> {
                }
                
                @Override
-               public double getLongitudalInertia() {
-                       return unitLongitudalInertia * stepCG.weight;
+               public double getLongitudinalInertia() {
+                       return unitLongitudinalInertia * stepCG.weight;
                }
                
                @Override