Merge pull request #442 from JoePfeiffer/fix-getAverageThrust
Fix getAverageThrust (fixes issue #441)
This commit is contained in:
commit
7177ca422c
@ -313,34 +313,31 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
|
|
||||||
if ( endTime <= time[timeIndex+1] ) {
|
if ( endTime <= time[timeIndex+1] ) {
|
||||||
// we are completely within this time slice so the computation of the average is pretty easy:
|
// we are completely within this time slice so the computation of the average is pretty easy:
|
||||||
double avgImpulse = MathUtil.map(startTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]);
|
double startThrust = MathUtil.map(startTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]);
|
||||||
avgImpulse += MathUtil.map(endTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]);
|
double endThrust = MathUtil.map(endTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]);
|
||||||
avgImpulse /= 2.0;
|
return (startThrust + endThrust) / 2.0;
|
||||||
return avgImpulse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// portion from startTime through time[timeIndex]
|
double impulse = 0.0;
|
||||||
double avgImpulse = 0.0;
|
|
||||||
// For numeric stability.
|
// portion from startTime through time[timeIndex+1]
|
||||||
if( time[timeIndex+1] - startTime > 0.001 ) {
|
double startThrust = MathUtil.map(startTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]);
|
||||||
avgImpulse = (MathUtil.map(startTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]) + thrust[timeIndex+1])
|
impulse = (time[timeIndex+1] - startTime) * (startThrust + thrust[timeIndex+1]) / 2.0;
|
||||||
/ 2.0 * (time[timeIndex+1] - startTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now add the whole steps;
|
// Now add the whole steps;
|
||||||
timeIndex++;
|
timeIndex++;
|
||||||
while ( timeIndex < time.length -1 && endTime >= time[timeIndex+1] ) {
|
while ( timeIndex < time.length -1 && endTime >= time[timeIndex+1] ) {
|
||||||
avgImpulse += (thrust[timeIndex] + thrust[timeIndex+1]) / 2.0 * (time[timeIndex+1]-time[timeIndex]);
|
impulse += (time[timeIndex+1] - time[timeIndex]) * (thrust[timeIndex] + thrust[timeIndex+1]) / 2.0;
|
||||||
timeIndex++;
|
timeIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now add the bit after the last time index
|
// Now add the bit after the last time index
|
||||||
if ( timeIndex < time.length -1 ) {
|
if ( timeIndex < time.length -1 ) {
|
||||||
double endInstImpulse = MathUtil.map( endTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]);
|
double endThrust = MathUtil.map( endTime, time[timeIndex], time[timeIndex+1], thrust[timeIndex], thrust[timeIndex+1]);
|
||||||
avgImpulse += (thrust[timeIndex] + endInstImpulse) / 2.0 * (endTime - time[timeIndex]);
|
impulse += (endTime - time[timeIndex]) * (thrust[timeIndex] + endThrust) / 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return avgImpulse / (endTime - startTime);
|
return impulse / (endTime - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user