From 99bdf71ba88e923719ec6af484f28c0a68c88766 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 17 Aug 2020 17:39:08 -0600 Subject: [PATCH] In FinSetCalc.calculateFinGeometry(), make sure x coordinates of interections between lines defining fins and strips being used to estimate geometry aren't beyond bounds of fin. --- .../sf/openrocket/aerodynamics/barrowman/FinSetCalc.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/aerodynamics/barrowman/FinSetCalc.java b/core/src/net/sf/openrocket/aerodynamics/barrowman/FinSetCalc.java index b70c7b246..8aef31d9f 100644 --- a/core/src/net/sf/openrocket/aerodynamics/barrowman/FinSetCalc.java +++ b/core/src/net/sf/openrocket/aerodynamics/barrowman/FinSetCalc.java @@ -293,8 +293,15 @@ public class FinSetCalc extends RocketComponentCalc { for (int i = i1; i <= i2; i++) { // Intersection point (x,y) + // Note that y can be outside the bounds of the line + // defined by (x1, y1) (x2 y2) so x can similarly be outside + // the bounds. If the line is nearly horizontal, it can be + // 'way outside. We want to get the whole "strip", so we + // don't clamp y; however, we do clamp x to avoid numerical + // instabilities double y = i * span / (DIVISIONS - 1); - double x = (y - y2) / (y1 - y2) * x1 + (y1 - y) / (y1 - y2) * x2; + double x = MathUtil.clamp((y - y2) / (y1 - y2) * x1 + (y1 - y) / (y1 - y2) * x2, + Math.min(x1, x2), Math.max(x1, x2)); if (x < chordLead[i]) chordLead[i] = x; if (x > chordTrail[i])