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.
This commit is contained in:
Robert Sammelson 2021-09-26 03:20:54 -04:00
parent 17ba70987a
commit e914b78052
No known key found for this signature in database
GPG Key ID: 2C8CCE48DB93839D

View File

@ -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 );