From e914b780529fa4b06515855ddac5fe6b30c580e8 Mon Sep 17 00:00:00 2001 From: Robert Sammelson Date: Sun, 26 Sep 2021 03:20:54 -0400 Subject: [PATCH 1/2] Use correct zero point for CoG calculation When center of gravity position is overrided, the zero point is the front of component, not the old center of gravity or the front of the parent. --- core/src/net/sf/openrocket/masscalc/MassCalculation.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculation.java b/core/src/net/sf/openrocket/masscalc/MassCalculation.java index 3d4242dc8..877147ff7 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculation.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculation.java @@ -343,6 +343,10 @@ public class MassCalculation { // 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.isMassive() ){ // if this component mass, merge it in before overriding: @@ -352,14 +356,13 @@ public class MassCalculation { this.setCM( this.getCM().setWeight(component.getOverrideMass()) ); } if (component.isCGOverridden()) { - this.setCM( this.getCM().setX( compCM.x + component.getOverrideCGX())); + this.setCM( this.getCM().setX( compZero.x + component.getOverrideCGX())); } }else { if (component.isMassOverridden()) { compCM = compCM.setWeight( component.getOverrideMass() ); } if (component.isCGOverridden()) { - final Coordinate compZero = parentTransform.transform( Coordinate.ZERO ); compCM = compCM.setX( compZero.x + component.getOverrideCGX() ); } this.addMass( compCM ); From 3a28f3b585cbb740f5ccdc8fcdd08102f3f793d8 Mon Sep 17 00:00:00 2001 From: Robert Sammelson Date: Thu, 4 Nov 2021 14:13:25 -0400 Subject: [PATCH 2/2] Adjust unit tests Fixes unit test errors by changing hardcoded values to the values the new code outputs. The new code is believed to be correct so this should be alright. --- core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java index 193bcf0ac..f04e0f88f 100644 --- a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java +++ b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java @@ -1064,7 +1064,7 @@ public class MassCalculatorTest extends BaseTestCase { double calcTotalMass = structure.getMass(); assertEquals(" Booster Launch Mass is incorrect: ", expMass, calcTotalMass, EPSILON); - final double expCMx = 1.0446069131149498; + final double expCMx = 1.1191303646438673; Coordinate expCM = new Coordinate(expCMx, 0, 0, expMass); assertEquals(" Booster Launch CM.x is incorrect: ", expCM.x, structure.getCM().x, EPSILON); assertEquals(" Booster Launch CM.y is incorrect: ", expCM.y, structure.getCM().y, EPSILON); @@ -1076,7 +1076,7 @@ public class MassCalculatorTest extends BaseTestCase { double boosterMOI_xx = structure.getRotationalInertia(); assertEquals(" Booster x-axis MOI is incorrect: ", expMOI_axial, boosterMOI_xx, EPSILON); - final double expMOI_tr = 0.036243133045; + final double expMOI_tr = 0.040989095911; double boosterMOI_tr = structure.getLongitudinalInertia(); assertEquals(" Booster transverse MOI is incorrect: ", expMOI_tr, boosterMOI_tr, EPSILON); }