From 4ce939fd1a1a6f9bf9eca5457b7ebc5e9c0b441c Mon Sep 17 00:00:00 2001 From: Bill Kuker Date: Wed, 15 Apr 2009 18:46:25 +0000 Subject: [PATCH] Allwo area calc on non-singular areas --- src/com/billkuker/rocketry/motorsim/grain/ShapeUtil.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/billkuker/rocketry/motorsim/grain/ShapeUtil.java b/src/com/billkuker/rocketry/motorsim/grain/ShapeUtil.java index 23e8e2d..7b2aba3 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/ShapeUtil.java +++ b/src/com/billkuker/rocketry/motorsim/grain/ShapeUtil.java @@ -19,10 +19,12 @@ public class ShapeUtil { * http://valis.cs.uiuc.edu/~sariel/research/CG/compgeom/msg00831.html * http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon * http://www.wikihow.com/Calculate-the-Area-of-a-Polygon + * According to http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u33.html + * this algorithm works OK with holes, and it seems to (see test) */ public static Amount area(java.awt.geom.Area a) { - if ( !a.isSingular() ) - throw new IllegalArgumentException("Can not calculate area of non-singular shape!"); + //if ( !a.isSingular() ) + //throw new IllegalArgumentException("Can not calculate area of non-singular shape!"); PathIterator i = a.getPathIterator(new AffineTransform(), .001); @@ -64,8 +66,9 @@ public class ShapeUtil { area = area / 2.0; // Result so far is double the signed area - if ( area < 0 ) //Depending on winding it could be negative + if ( area < 0 ){ //Depending on winding it could be negative area = area * -1.0; + } return Amount.valueOf(area, SI.MILLIMETER.pow(2)).to(Area.UNIT); -- 2.47.2