From e7e96ca715c39e4da7edc0772b4e038aded31c03 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 3 Mar 2022 02:50:53 +0100 Subject: [PATCH 1/8] [#1204] Fix overrideCGX slider length --- .../configdialog/RocketComponentConfig.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java index 55b4dce42..c963aa6a2 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java @@ -6,7 +6,6 @@ import java.awt.Container; import java.awt.event.*; import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -340,15 +339,30 @@ public class RocketComponentConfig extends JPanel { // Calculate suitable length for slider DoubleModel length; if (component instanceof ComponentAssembly) { - double l = 0; - Iterator iterator = component.iterator(false); + double minL = Double.MAX_VALUE; + double maxL = Double.MIN_VALUE; + while (iterator.hasNext()) { RocketComponent c = iterator.next(); - if (c.getAxialMethod() == AxialMethod.AFTER) - l += c.getLength(); + + double compPos = c.getAxialOffset(AxialMethod.ABSOLUTE); + if (compPos < minL) { + minL = compPos; + } + + double compLen = c.getLength(); + if (c instanceof FinSet) { + compLen = ((FinSet) c).getInstanceBoundingBox().span().x; + } + if (compPos + compLen > maxL) { + maxL = compPos + compLen; + } } - length = new DoubleModel(l); + length = new DoubleModel(maxL - minL); + } else if (component instanceof FinSet) { + double compLen = ((FinSet) component).getInstanceBoundingBox().span().x; + length = new DoubleModel(compLen); } else { length = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0); } From e82a7a89b243258350d25e09b51d8dfed1d2436f Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 4 Mar 2022 18:10:44 +0100 Subject: [PATCH 2/8] Add helper methods --- .../rocketcomponent/RocketComponent.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 43fad2d51..bcdca0897 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -1623,6 +1623,23 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab checkState(); return parent; } + + /** + * Get all the parent and super-parent components of this component. + * @return parent and super-parents of this component + */ + public final List getParents() { + checkState(); + List result = new LinkedList<>(); + RocketComponent currComp = this; + + while (currComp.parent != null) { + currComp = currComp.parent; + result.add(currComp); + } + + return result; + } /** * Get the root component of the component tree. @@ -1710,6 +1727,26 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab } return result; } + + /** + * Return all the component assemblies that are a parent or super-parent of this component + * @return list of ComponentAssembly components that are a parent or super-parent of this component + */ + public final List getParentAssemblies() { + checkState(); + + List result = new LinkedList<>(); + RocketComponent currComp = this; + + while (currComp.parent != null) { + currComp = currComp.parent; + if (currComp instanceof ComponentAssembly) { + result.add(currComp); + } + } + + return result; + } /** From 3fcd942ee4089ef8ac068a95651e5f6fee36cdbd Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 4 Mar 2022 18:11:15 +0100 Subject: [PATCH 3/8] Add documentation --- core/src/net/sf/openrocket/masscalc/RigidBody.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/net/sf/openrocket/masscalc/RigidBody.java b/core/src/net/sf/openrocket/masscalc/RigidBody.java index 01543c58b..9c1ad7aab 100644 --- a/core/src/net/sf/openrocket/masscalc/RigidBody.java +++ b/core/src/net/sf/openrocket/masscalc/RigidBody.java @@ -76,6 +76,11 @@ public class RigidBody { MathUtil.equals(this.Izz, other.Izz)) ; } + /** + * Rebase the current moment of inertia from this.cm reference system to newLocation reference system + * @param newLocation new moment of inertia reference system + * @return RigidBody with rebased moment of inertia + */ public RigidBody rebase( final Coordinate newLocation ){ final Coordinate delta = this.cm.sub( newLocation ).setWeight(0.); double x2 = pow2(delta.x); From d661cf12aa18f8abb2cd773bf50b5e30343b4c68 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 5 Mar 2022 00:35:45 +0100 Subject: [PATCH 4/8] Fix overrideCG slider length for non-assembly components --- .../sf/openrocket/gui/configdialog/RocketComponentConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java index c963aa6a2..66c94148e 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java @@ -338,8 +338,8 @@ public class RocketComponentConfig extends JPanel { m = new DoubleModel(component, "OverrideCGX", UnitGroup.UNITS_LENGTH, 0); // Calculate suitable length for slider DoubleModel length; - if (component instanceof ComponentAssembly) { - Iterator iterator = component.iterator(false); + if (component.getChildCount() > 0) { + Iterator iterator = component.iterator(true); double minL = Double.MAX_VALUE; double maxL = Double.MIN_VALUE; From ec4e6eed37b90065bb7555b2abe1e4fc53159f92 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 5 Mar 2022 15:49:26 +0100 Subject: [PATCH 5/8] [#1204] Add CG override effect to motors The problem was that the overrideCG had no effect in calculateMotors(). --- .../openrocket/masscalc/MassCalculation.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculation.java b/core/src/net/sf/openrocket/masscalc/MassCalculation.java index 03724b1f8..3e985ec1d 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculation.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculation.java @@ -71,6 +71,10 @@ public class MassCalculation { this.centerOfMass = this.centerOfMass.average( pointMass); } } + + public void addMass(double mass) { + this.centerOfMass = this.centerOfMass.setWeight(getMass() + mass); + } public MassCalculation copy( final RocketComponent _root, final Transformation _transform){ return new MassCalculation( this.type, this.config, this.simulationTime, this.activeMotorList, _root, _transform, this.analysisMap); @@ -83,6 +87,10 @@ public class MassCalculation { public double getMass() { return this.centerOfMass.weight; } + + public void setMass(double mass) { + this.centerOfMass = this.centerOfMass.setWeight(mass); + } public double getLongitudinalInertia() { return this.inertia.Iyy; @@ -407,6 +415,13 @@ public class MassCalculation { final int instanceCount = component.getInstanceCount(); Coordinate[] instanceLocations = component.getInstanceLocations(); + if (analysisMap != null) { + if (this.config.isComponentActive(component) && (!analysisMap.containsKey(component.hashCode()))) { + CMAnalysisEntry entry = new CMAnalysisEntry(component); + analysisMap.put(component.hashCode(), entry); + } + } + // // vvv DEBUG // if( this.config.isComponentActive(component) ){ // System.err.println(String.format( "%s[%s]....", prefix, component.getName())); @@ -448,6 +463,45 @@ public class MassCalculation { this.merge( children ); //System.err.println(String.format( "%s....assembly mass (incl/children): %s", prefix, this.toCMDebug())); } + + if (this.config.isComponentActive(component) ){ + Coordinate compCM = component.getComponentCG(); + + // mass data for *this component only* in the rocket-frame + compCM = parentTransform.transform(compCM.add(component.getPosition())); + + // setting zero as the CG position means the top of the component, which is component.getPosition() + final Coordinate compZero = parentTransform.transform( component.getPosition() ); + + if (component.getOverrideSubcomponents()) { + if (component.isCGOverridden()) { + this.setCM(this.getCM().setX(compZero.x + component.getOverrideCGX())); + } + } else { + if (component.isCGOverridden()) { + compCM = compCM.setX(compZero.x + component.getOverrideCGX()); + } + } + + if (null != analysisMap) { + final CMAnalysisEntry entry = analysisMap.get(component.hashCode()); + if (component.getChildCount() > 0) { + // For parent components, record the _assembly_ information + entry.updateEachMass(children.getMass() / component.getInstanceCount()); + entry.updateAverageCM(this.centerOfMass); + } else { + // For actual components, record the mass of the component, and disregard children + entry.updateEachMass(compCM.weight); + entry.updateAverageCM(compCM); + } + } + + final double compIx = component.getRotationalUnitInertia() * compCM.weight; + final double compIt = component.getLongitudinalUnitInertia() * compCM.weight; + final RigidBody componentInertia = new RigidBody(compCM, compIx, compIt, compIt); + this.addInertia(componentInertia); + } + // // vvv DEBUG // if( this.config.isComponentActive(component) && 0 < this.getMass() ) { From 0dc7c306fe7d096cf28820f49a47724b3f64e978 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 5 Mar 2022 16:41:00 +0100 Subject: [PATCH 6/8] [#1204] Remove inertia update in calculateMotors --- core/src/net/sf/openrocket/masscalc/MassCalculation.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculation.java b/core/src/net/sf/openrocket/masscalc/MassCalculation.java index 3e985ec1d..0be41295e 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculation.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculation.java @@ -495,11 +495,6 @@ public class MassCalculation { entry.updateAverageCM(compCM); } } - - final double compIx = component.getRotationalUnitInertia() * compCM.weight; - final double compIt = component.getLongitudinalUnitInertia() * compCM.weight; - final RigidBody componentInertia = new RigidBody(compCM, compIx, compIt, compIt); - this.addInertia(componentInertia); } From 7255756e797202867af622e113883c011c93d494 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sun, 6 Mar 2022 02:35:22 +0100 Subject: [PATCH 7/8] Undo #1204 changes --- .../openrocket/masscalc/MassCalculation.java | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculation.java b/core/src/net/sf/openrocket/masscalc/MassCalculation.java index 0be41295e..28bc0de5b 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculation.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculation.java @@ -415,13 +415,6 @@ public class MassCalculation { final int instanceCount = component.getInstanceCount(); Coordinate[] instanceLocations = component.getInstanceLocations(); - if (analysisMap != null) { - if (this.config.isComponentActive(component) && (!analysisMap.containsKey(component.hashCode()))) { - CMAnalysisEntry entry = new CMAnalysisEntry(component); - analysisMap.put(component.hashCode(), entry); - } - } - // // vvv DEBUG // if( this.config.isComponentActive(component) ){ // System.err.println(String.format( "%s[%s]....", prefix, component.getName())); @@ -464,39 +457,6 @@ public class MassCalculation { //System.err.println(String.format( "%s....assembly mass (incl/children): %s", prefix, this.toCMDebug())); } - if (this.config.isComponentActive(component) ){ - Coordinate compCM = component.getComponentCG(); - - // mass data for *this component only* in the rocket-frame - compCM = parentTransform.transform(compCM.add(component.getPosition())); - - // setting zero as the CG position means the top of the component, which is component.getPosition() - final Coordinate compZero = parentTransform.transform( component.getPosition() ); - - if (component.getOverrideSubcomponents()) { - if (component.isCGOverridden()) { - this.setCM(this.getCM().setX(compZero.x + component.getOverrideCGX())); - } - } else { - if (component.isCGOverridden()) { - compCM = compCM.setX(compZero.x + component.getOverrideCGX()); - } - } - - if (null != analysisMap) { - final CMAnalysisEntry entry = analysisMap.get(component.hashCode()); - if (component.getChildCount() > 0) { - // For parent components, record the _assembly_ information - entry.updateEachMass(children.getMass() / component.getInstanceCount()); - entry.updateAverageCM(this.centerOfMass); - } else { - // For actual components, record the mass of the component, and disregard children - entry.updateEachMass(compCM.weight); - entry.updateAverageCM(compCM); - } - } - } - // // vvv DEBUG // if( this.config.isComponentActive(component) && 0 < this.getMass() ) { From 73044b35701159d4fa097b3fb993ccaafe7dc8a7 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sun, 6 Mar 2022 02:36:49 +0100 Subject: [PATCH 8/8] Update overridden text message --- core/resources/l10n/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 650a40db7..9e4a2782b 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -885,7 +885,7 @@ RocketCompCfg.checkbox.Overridemass = Override mass: RocketCompCfg.checkbox.Overridecenterofgrav = Override center of gravity: RocketCompCfg.checkbox.SetDragCoeff = Set coefficient of drag: RocketCompCfg.checkbox.OverridemassandCG = Override mass and CG of all subcomponents -RocketCompCfg.lbl.longB1 = The overridden mass does not include motors.
+RocketCompCfg.lbl.longB1 = The overridden mass and center of gravity does not include motors.
RocketCompCfg.lbl.longB2 = The center of gravity is measured from the front end of the RocketCompCfg.lbl.Commentsonthe = Comments on the RocketCompCfg.lbl.Figurestyle = Figure style: