From 7aaaf4bce9b89a0a5091b1595adde932da45c1eb Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 9 May 2023 01:24:11 +0200 Subject: [PATCH 1/3] Don't calculate fillet volume is no fillet --- core/src/net/sf/openrocket/rocketcomponent/FinSet.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index dd033566c..2d25a8eb8 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -581,7 +581,8 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona * 5. Return twice that since there is a fillet on each side of the fin. */ protected Coordinate calculateFilletVolumeCentroid() { - if((null == this.parent) || (!SymmetricComponent.class.isAssignableFrom(this.parent.getClass()))){ + if ((this.filletRadius == 0) || (this.parent == null) || + (!SymmetricComponent.class.isAssignableFrom(this.parent.getClass()))) { return Coordinate.ZERO; } Coordinate[] mountPoints = this.getRootPoints(); @@ -594,7 +595,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona final Coordinate finLead = getFinFront(); final double xFinEnd = finLead.x + getLength(); final Coordinate[] rootPoints = getMountPoints( finLead.x, xFinEnd, -finLead.x, -finLead.y); - if (0 == rootPoints.length) { + if (rootPoints.length == 0) { return Coordinate.ZERO; } @@ -624,7 +625,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona if (finCount == 1) { Transformation rotation = Transformation.rotate_x( getAngleOffset()); return rotation.transform(filletVolumeCentroid); - }else{ + } else{ return filletVolumeCentroid.setY(0.); } } From ab878a82f06cda8b3113e4e45af06ab000a66746 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 11 May 2023 21:06:51 +0200 Subject: [PATCH 2/3] [#2209] Average segment centroids --- .../net/sf/openrocket/rocketcomponent/FinSet.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 2d25a8eb8..ed675b502 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -544,7 +544,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona return centerOfMass; } - private static Coordinate calculateFilletCrossSection(final double filletRadius, final double bodyRadius){ + private static Coordinate calculateFilletCrossSection(final double filletRadius, final double bodyRadius) { final double hypotenuse = filletRadius + bodyRadius; final double innerArcAngle = Math.asin(filletRadius / hypotenuse); final double outerArcAngle = Math.acos(filletRadius / hypotenuse); @@ -554,17 +554,17 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona - outerArcAngle * filletRadius * filletRadius / 2 - innerArcAngle * bodyRadius * bodyRadius / 2); - if(Double.isNaN(crossSectionArea)) { + if (Double.isNaN(crossSectionArea)) { crossSectionArea = 0.; - }else { + } else { // each fin has a fillet on each side crossSectionArea *= 2; } // heuristic, relTo the body center - double yCentroid = bodyRadius + filletRadius /5; + double yCentroid = bodyRadius + filletRadius / 5; - return new Coordinate(0,yCentroid,0,crossSectionArea); + return new Coordinate(0, yCentroid, 0, crossSectionArea); } /* @@ -617,7 +617,7 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona final Coordinate segmentCentroid = segmentCrossSection.setWeight(segmentVolume); - filletVolumeCentroid = filletVolumeCentroid.add(segmentCentroid); + filletVolumeCentroid = filletVolumeCentroid.average(segmentCentroid); prev = cur; } From 22e99e8534d585556ab7a44574df66a10f7e7127 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 11 May 2023 21:31:36 +0200 Subject: [PATCH 3/3] Add unit tests for fillets on transition --- .../rocketcomponent/TrapezoidFinSetTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/core/test/net/sf/openrocket/rocketcomponent/TrapezoidFinSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/TrapezoidFinSetTest.java index cab506755..d047b2eff 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/TrapezoidFinSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/TrapezoidFinSetTest.java @@ -52,6 +52,32 @@ public class TrapezoidFinSetTest extends BaseTestCase { return rkt; } + private Rocket createFreeformFinOnTransition() { + final Rocket rkt = new Rocket(); + final AxialStage stg = new AxialStage(); + rkt.addChild(stg); + Transition transition = new Transition(); + transition.setLength(0.2); + transition.setForeRadius(0.1); + transition.setAftRadius(0.3); + transition.setShapeType(Transition.Shape.OGIVE); + stg.addChild(transition); + FreeformFinSet fins = new FreeformFinSet(); + fins.setFinCount(1); + fins.setAxialOffset(AxialMethod.MIDDLE, 0.0); + fins.setMaterial(Material.newMaterial(Material.Type.BULK, "Fin-Test-Material", 1.0, true)); + fins.setThickness(0.005); // == 5 mm + + transition.addChild(fins); + + fins.setTabLength(0.00); + + fins.setFilletRadius(0.0); + + rkt.enableEvents(); + return rkt; + } + @Test public void testMultiplicity() { final TrapezoidFinSet trapFins = new TrapezoidFinSet(); @@ -187,6 +213,33 @@ public class TrapezoidFinSetTest extends BaseTestCase { } } + @Test + public void testFilletCalculationsOnTransition() { + final Rocket rkt = createFreeformFinOnTransition(); + Transition transition = (Transition) rkt.getChild(0).getChild(0); + FinSet fins = (FinSet) rkt.getChild(0).getChild(0).getChild(0); + + fins.setFilletRadius(0.005); + fins.setFilletMaterial(Material.newMaterial(Material.Type.BULK, "Fillet-Test-Material", 1.0, true)); + + // used for fillet and edge calculations: + // + // [1] +--+ [2] + // / \ + // / \ + // [0] +--------+ [3] + // + assertEquals(0.05, fins.getLength(), EPSILON); + assertEquals("Transition fore radius doesn't match: ", 0.1, transition.getForeRadius(), EPSILON); + assertEquals("Transition aft radius doesn't match: ", 0.3, transition.getAftRadius(), EPSILON); + + final Coordinate actVolume = fins.calculateFilletVolumeCentroid(); + + assertEquals("Fin volume doesn't match: ", 5.973e-07, actVolume.weight, EPSILON); + assertEquals("Fin mass center.x doesn't match: ", 0.024393025, actVolume.x, EPSILON); + assertEquals("Fin mass center.y doesn't match: ", 0.190479957, actVolume.y, EPSILON); + } + @Test public void testTrapezoidCGComputation() { {