From 458a5a0605d52a10a396bc73b1dd1ed7a64d6ee7 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 30 Nov 2022 15:15:04 +0100 Subject: [PATCH] Catch bug of negative fin area weight --- core/src/net/sf/openrocket/rocketcomponent/FinSet.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 45e0b2a1d..0dc515dea 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -644,7 +644,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona // calculate marginal area final double delta_x = (cur.x - prev.x); - final double y_avg = (cur.y + prev.y)*0.5; + final double y_avg = (cur.y + prev.y)*0.5; // TODO: MEDIUM: what if one of the points is below the x-axis? (can produce negative area) double area_increment = delta_x*y_avg; if( MathUtil.equals( 0, area_increment)){ prev = cur; @@ -662,6 +662,11 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona prev=cur; } + + // Negative weight => make positive. TODO: This is NOT a correct solution, but at least it won't throw an exception... + if (centroidSum.weight < 0) { + centroidSum = new Coordinate(centroidSum.x, -centroidSum.y, centroidSum.z, Math.abs(centroidSum.weight)); + } return centroidSum; }