Made an ExtrudedGrain
authorBill Kuker <bkuker@billkuker.com>
Wed, 22 Apr 2009 20:43:45 +0000 (20:43 +0000)
committerBill Kuker <bkuker@billkuker.com>
Wed, 22 Apr 2009 20:43:45 +0000 (20:43 +0000)
src/com/billkuker/rocketry/motorsim/grain/ExtrudedShapeGrain.java

index e934c1a0df573b871778be2324a82a110139d572..ede26b6616f532e9b488bd5cd5456fd0eb99b7a4 100644 (file)
@@ -13,12 +13,14 @@ import javax.measure.unit.SI;
 \r
 import org.jscience.physics.amount.Amount;\r
 \r
+import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;\r
+\r
 import com.billkuker.rocketry.motorsim.Grain;\r
 import com.billkuker.rocketry.motorsim.MotorPart;\r
 import com.billkuker.rocketry.motorsim.visual.Editor;\r
 import com.billkuker.rocketry.motorsim.visual.GrainPanel;\r
 \r
-public class ExtrudedShapeGrain extends MotorPart implements Grain {\r
+public class ExtrudedShapeGrain extends ExtrudedGrain {\r
        \r
        public static ExtrudedShapeGrain DEFAULT_GRAIN = new ExtrudedShapeGrain(){\r
                {\r
@@ -28,7 +30,8 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                                xsection.inhibit(outside);\r
                                xsection.subtract(new Ellipse2D.Double(10,10, 10, 10));\r
                                setLength(Amount.valueOf(70, SI.MILLIMETER));\r
-                               setEndSurfaceInhibited(false);\r
+                               setForeEndInhibited(false);\r
+                               setAftEndInhibited(false);\r
                        } catch ( Exception e ){\r
                                throw new Error(e);\r
                        }\r
@@ -36,11 +39,7 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
        };\r
 \r
        protected BurningShape xsection = new BurningShape();\r
-\r
-       Amount<Length> length = Amount.valueOf(25, SI.MILLIMETER);\r
        \r
-       boolean endSurfaceInhibited = false;\r
-\r
        Amount<Length> rStep;\r
 \r
        Amount<Length> webThickness;\r
@@ -51,9 +50,7 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                if (regression.isGreaterThan(webThickness()))\r
                        return zero;\r
                \r
-               Amount<Length> rLen = length;\r
-               if ( !endSurfaceInhibited ) //Regress length if uninhibited\r
-                       rLen = length.minus(regression.times(2));\r
+               Amount<Length> rLen = regressedLength(regression);\r
                \r
                if (rLen.isLessThan(Amount.valueOf(0, SI.MILLIMETER)))\r
                        return zero;\r
@@ -67,17 +64,18 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                                SI.MILLIMETER))));\r
        \r
                Amount<Area> xSection = ShapeUtil.area(xsection.getShape(regression));\r
+               \r
+               Amount<Area> sides = ShapeUtil.perimeter(burn).divide(2).times(rLen).to(Area.UNIT);\r
+               Amount<Area> ends = xSection.times(numberOfBurningEnds(regression));\r
+               \r
+               return sides.plus(ends);\r
 \r
-               return ShapeUtil.perimeter(burn).divide(2).times(rLen).plus(\r
-                               xSection.times(2)).to(Area.UNIT);\r
        }\r
 \r
        public Amount<Volume> volume(Amount<Length> regression) {\r
                Amount<Volume> zero = Amount.valueOf(0, Volume.UNIT);\r
                \r
-               Amount<Length> rLen = length;\r
-               if ( !endSurfaceInhibited ) //Regress length if uninhibited\r
-                       rLen = length.minus(regression.times(2));\r
+               Amount<Length> rLen = regressedLength(regression);\r
                \r
                if (rLen.isLessThan(Amount.valueOf(0, SI.MILLIMETER)))\r
                        return zero;\r
@@ -114,8 +112,11 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                                break;\r
                }\r
                webThickness = Amount.valueOf(guess, SI.MILLIMETER);\r
-               if (webThickness.isGreaterThan(length.divide(2)))\r
-                       webThickness = length.divide(2);\r
+               \r
+               //TODO Need to check # of burning ends!\r
+               if (webThickness.isGreaterThan(getLength().divide(2)))\r
+                       webThickness = getLength().divide(2);\r
+               \r
                return webThickness;\r
        }\r
 \r
@@ -126,12 +127,11 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
        public java.awt.geom.Area getSideView(Amount<Length> regression) {\r
                java.awt.geom.Area res = new java.awt.geom.Area();\r
                \r
-               Amount<Length> rLen = length;\r
-               if ( !endSurfaceInhibited ) //Regress length if uninhibited\r
-                       rLen = length.minus(regression.times(2));\r
+               Amount<Length> rLen = regressedLength(regression);\r
                \r
                double rLenmm = rLen.doubleValue(SI.MILLIMETER);\r
                \r
+               //TODO Shift up or down based on burning ends\r
                for( java.awt.geom.Area a : ShapeUtil.separate(getCrossSection(regression))){\r
                        Rectangle2D bounds = a.getBounds2D();\r
                        Rectangle2D side = new Rectangle2D.Double(bounds.getMinX(), -rLenmm/2.0, bounds.getWidth(), rLenmm);\r
@@ -139,29 +139,6 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain {
                }\r
                return res;\r
        }\r
-\r
-       public Amount<Length> getLength() {\r
-               return length;\r
-       }\r
-\r
-       public void setLength(Amount<Length> length) throws PropertyVetoException {\r
-               fireVetoableChange("length", this.length, length);\r
-               Amount<Length> old = this.length;\r
-               this.length = length;\r
-               firePropertyChange("length", old, length);\r
-       }\r
-\r
-       public boolean isEndSurfaceInhibited() {\r
-               return endSurfaceInhibited;\r
-       }\r
-\r
-       public void setEndSurfaceInhibited(boolean endSurfaceInhibited) throws PropertyVetoException {\r
-               fireVetoableChange("endSurfaceInhibited", this.endSurfaceInhibited, endSurfaceInhibited);\r
-               boolean old = this.endSurfaceInhibited;\r
-               this.endSurfaceInhibited = endSurfaceInhibited;\r
-               firePropertyChange("endSurfaceInhibited", old, endSurfaceInhibited);\r
-       }\r
-\r
        \r
        public static void main(String args[]) throws Exception {\r
                ExtrudedShapeGrain e = DEFAULT_GRAIN;\r