Merge pull request #1604 from SiboVG/issue-1315

[#1315] Update auto length in MassObject
This commit is contained in:
Joe Pfeiffer 2022-08-28 17:39:31 -06:00 committed by GitHub
commit 5e20c5c3fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 23 deletions

View File

@ -13,7 +13,7 @@ public class MassObjectSaver extends InternalComponentSaver {
MassObject mass = (MassObject) c;
elements.add("<packedlength>" + mass.getLength() + "</packedlength>");
elements.add("<packedlength>" + mass.getLengthNoAuto() + "</packedlength>");
if (mass.isRadiusAutomatic()) {
elements.add("<packedradius>auto " + mass.getRadiusNoAuto() + "</packedradius>");
} else {

View File

@ -12,6 +12,7 @@ import net.sf.openrocket.file.rocksim.RocksimLocationMode;
import net.sf.openrocket.file.rocksim.importt.BaseHandler;
import net.sf.openrocket.rocketcomponent.ExternalComponent;
import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.MassObject;
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
import net.sf.openrocket.rocketcomponent.RingComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -83,7 +84,7 @@ public abstract class BasePartDTO {
setKnownCG(ec.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
setKnownMass(ec.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
if (! (ec instanceof FinSet)) {
if (!(ec instanceof FinSet)) {
setLen(ec.getLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
}
setUseKnownCG(ec.isCGOverridden() || ec.isMassOverridden() ? 1 : 0);

View File

@ -50,7 +50,21 @@ public abstract class MassObject extends InternalComponent {
return false;
}
@Override
public double getLength() {
if (this.autoRadius) {
// Calculate the parachute volume using the non auto radius and the non auto length, and transform that back
// to the auto radius situation to get the auto radius length (the volume in both situations is the same).
double parachuteVolume = Math.pow(this.radius, 2) * this.length; // Math.PI left out, not needed
return parachuteVolume / Math.pow(getRadius(), 2);
}
return length;
}
public double getLengthNoAuto() {
return length;
}
public void setLength(double length) {
for (RocketComponent listener : configListeners) {
if (listener instanceof MassObject) {
@ -59,10 +73,20 @@ public abstract class MassObject extends InternalComponent {
}
length = Math.max(length, 0);
if (MathUtil.equals(this.length, length)) {
return;
if (this.autoRadius) {
// Calculate the parachute volume using the auto radius and the new "auto" length, and transform that back
// to the non auto radius situation to set this.length (the volume in both situations is the same).
double parachuteVolume = Math.pow(getRadius(), 2) * length; // Math.PI left out, not needed
double newLength = parachuteVolume / Math.pow(this.radius, 2);
if (MathUtil.equals(this.length, newLength))
return;
this.length = newLength;
} else {
if (MathUtil.equals(this.length, length)) {
return;
}
this.length = length;
}
this.length = length;
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
@ -114,8 +138,8 @@ public abstract class MassObject extends InternalComponent {
public void setRadiusAutomatic(boolean auto) {
for (RocketComponent listener : configListeners) {
if (listener instanceof Parachute) {
((Parachute) listener).setRadiusAutomatic(auto);
if (listener instanceof MassObject) {
((MassObject) listener).setRadiusAutomatic(auto);
}
}
@ -124,6 +148,10 @@ public abstract class MassObject extends InternalComponent {
autoRadius = auto;
// Set the length
double parachuteVolume = (Math.PI * Math.pow(getRadius(), 2) * length);
length = parachuteVolume / (Math.PI * Math.pow(getRadius(), 2));
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}

View File

@ -18,8 +18,6 @@ public class Parachute extends RecoveryDevice {
private int lineCount;
private final double DEFAULT_LINE_LENGTH = 0.3;
private double lineLength;
private final double InitialPackedLength = this.length;
private final double InitialPackedRadius = this.radius;
public Parachute() {
this.diameter = DEFAULT_DIAMETER;
@ -213,23 +211,15 @@ public class Parachute extends RecoveryDevice {
// // Set preset parachute packed length
if ((preset.has(ComponentPreset.PACKED_LENGTH)) && preset.get(ComponentPreset.PACKED_LENGTH) > 0) {
this.PackedLength = preset.get(ComponentPreset.PACKED_LENGTH);
length = PackedLength;
} else {
length = InitialPackedLength;
length = preset.get(ComponentPreset.PACKED_LENGTH);
}
// // Set preset parachute packed diameter
if ((preset.has(ComponentPreset.PACKED_DIAMETER)) && preset.get(ComponentPreset.PACKED_DIAMETER) > 0) {
this.PackedDiameter = preset.get(ComponentPreset.PACKED_DIAMETER);
radius = PackedDiameter / 2;
} else {
radius = InitialPackedRadius;
radius = preset.get(ComponentPreset.PACKED_DIAMETER) / 2;
}
// // Size parachute packed diameter within parent inner diameter
if (length > 0 && radius > 0) {
double parachuteVolume = (Math.PI * Math.pow(radius, 2) * length);
setRadiusAutomatic(true);
length = parachuteVolume / (Math.PI * Math.pow(getRadius(), 2));
}
// SUBSTITUTE / ACTIVATE Override Mass Preset

View File

@ -19,9 +19,6 @@ import net.sf.openrocket.util.MathUtil;
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
public abstract class RecoveryDevice extends MassObject implements FlightConfigurableComponent {
////
protected double PackedDiameter;
protected double PackedLength;
////
protected double DragCoefficient;
protected double cd = Parachute.DEFAULT_CD;