Add Star grain
authorBill Kuker <bkuker@billkuker.com>
Thu, 4 Nov 2010 17:38:31 +0000 (17:38 +0000)
committerBill Kuker <bkuker@billkuker.com>
Thu, 4 Nov 2010 17:38:31 +0000 (17:38 +0000)
gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorEditor.java
src/com/billkuker/rocketry/motorsim/grain/Star.java [new file with mode: 0644]
test.html [new file with mode: 0644]

index 690beb1e5245b2ef20a007b5cbe8fb97702a3f50..988ad6c53a7c3349061b87a0432050a0e0f876d7 100644 (file)
@@ -57,6 +57,7 @@ import com.billkuker.rocketry.motorsim.grain.Finocyl;
 import com.billkuker.rocketry.motorsim.grain.Moonburner;\r
 import com.billkuker.rocketry.motorsim.grain.MultiGrain;\r
 import com.billkuker.rocketry.motorsim.grain.RodAndTubeGrain;\r
+import com.billkuker.rocketry.motorsim.grain.Star;\r
 import com.billkuker.rocketry.motorsim.io.MotorIO;\r
 import com.billkuker.rocketry.motorsim.visual.BurnPanel;\r
 import com.billkuker.rocketry.motorsim.visual.Editor;\r
@@ -84,6 +85,7 @@ public class MotorEditor extends JTabbedPane implements PropertyChangeListener {
        {\r
                grainTypes.add(CoredCylindricalGrain.class);\r
                grainTypes.add(Finocyl.class);\r
+               grainTypes.add(Star.class);\r
                grainTypes.add(Moonburner.class);\r
                grainTypes.add(RodAndTubeGrain.class);\r
                grainTypes.add(CSlot.class);\r
diff --git a/src/com/billkuker/rocketry/motorsim/grain/Star.java b/src/com/billkuker/rocketry/motorsim/grain/Star.java
new file mode 100644 (file)
index 0000000..dc1d125
--- /dev/null
@@ -0,0 +1,121 @@
+package com.billkuker.rocketry.motorsim.grain;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.Area;\r
+import java.awt.geom.Ellipse2D;\r
+import java.awt.geom.GeneralPath;\r
+import java.beans.PropertyVetoException;\r
+\r
+import javax.measure.quantity.Length;\r
+import javax.measure.unit.SI;\r
+\r
+import org.jscience.physics.amount.Amount;\r
+\r
+import com.billkuker.rocketry.motorsim.Validating;\r
+import com.billkuker.rocketry.motorsim.grain.util.BurningShape;\r
+import com.billkuker.rocketry.motorsim.grain.util.ExtrudedShapeGrain;\r
+import com.billkuker.rocketry.motorsim.visual.Editor;\r
+import com.billkuker.rocketry.motorsim.visual.GrainPanel;\r
+\r
+public class Star extends ExtrudedShapeGrain implements Validating {\r
+       private Amount<Length> oD = Amount.valueOf(30, SI.MILLIMETER);\r
+       private Amount<Length> iD = Amount.valueOf(5, SI.MILLIMETER);\r
+       private Amount<Length> pD = Amount.valueOf(15, SI.MILLIMETER);\r
+       private int pointCount = 5;\r
+       \r
+       public Star(){\r
+               try {\r
+                       setLength(Amount.valueOf(70, SI.MILLIMETER));\r
+               } catch (PropertyVetoException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               generateGeometry();\r
+       }\r
+       \r
+       private void generateGeometry(){\r
+               double odmm = oD.doubleValue(SI.MILLIMETER);\r
+               double idmm = iD.doubleValue(SI.MILLIMETER)/2.0;\r
+               double pdmm = pD.doubleValue(SI.MILLIMETER)/2.0;\r
+               \r
+               xsection = new BurningShape();\r
+               Shape outside = new Ellipse2D.Double(-odmm/2, -odmm/2, odmm, odmm);\r
+               xsection.add(outside);\r
+               xsection.inhibit(outside);\r
+               //xsection.subtract(new Ellipse2D.Double(-idmm/2, -idmm/2, idmm, idmm));\r
+               webThickness = null;\r
+               \r
+               GeneralPath p = new GeneralPath();\r
+               double theta = 0;\r
+               double dTheta = (2.0 * Math.PI) / ( pointCount * 2.0 );\r
+               p.moveTo(0, idmm);\r
+               for ( int i = 0; i < pointCount; i++ ){\r
+                       theta += dTheta;\r
+                       p.lineTo(pdmm*Math.sin(theta), pdmm*Math.cos(theta));\r
+                       theta += dTheta;\r
+                       p.lineTo(idmm*Math.sin(theta), idmm*Math.cos(theta));\r
+               }\r
+               p.closePath();\r
+               xsection.subtract(new Area(p));\r
+       }\r
+       \r
+       public Amount<Length> getOD() {\r
+               return oD;\r
+       }\r
+\r
+       public void setOD(Amount<Length> od) throws PropertyVetoException {\r
+               if (od.equals(this.oD))\r
+                       return;\r
+               this.oD = od;\r
+               generateGeometry();\r
+       }\r
+\r
+       public Amount<Length> getID() {\r
+               return iD;\r
+       }\r
+\r
+       public void setID(Amount<Length> id) throws PropertyVetoException {\r
+               if (id.equals(this.iD))\r
+                       return;\r
+               iD = id;\r
+               generateGeometry();\r
+       }\r
+       \r
+       public Amount<Length> getPointDiameter() {\r
+               return pD;\r
+       }\r
+\r
+       public void setPointDiameter(Amount<Length> pd) throws PropertyVetoException {\r
+               if (pd.equals(this.pD))\r
+                       return;\r
+               pD = pd;\r
+               generateGeometry();\r
+       }\r
+       \r
+       public int getPointCount(){\r
+               return pointCount;\r
+       }\r
+       \r
+       public void setPointCount(final int points){\r
+               pointCount = points;\r
+               generateGeometry();\r
+       }\r
+       \r
+       \r
+       public static void main(String args[]) throws Exception {\r
+               Star e = new Star();\r
+               new Editor(e).showAsWindow();\r
+               new GrainPanel(e).showAsWindow();\r
+       }\r
+       \r
+       @Override\r
+       public void validate() throws ValidationException{\r
+               if ( iD.equals(Amount.ZERO) )\r
+                       throw new ValidationException(this, "Invalid iD");\r
+               if ( oD.equals(Amount.ZERO) )\r
+                       throw new ValidationException(this, "Invalid oD");\r
+               if ( getLength().equals(Amount.ZERO) )\r
+                       throw new ValidationException(this, "Invalid Length");\r
+               if ( iD.isGreaterThan(oD) )\r
+                       throw new ValidationException(this, "iD > oD");         \r
+       }\r
+}\r
diff --git a/test.html b/test.html
new file mode 100644 (file)
index 0000000..af91040
--- /dev/null
+++ b/test.html
@@ -0,0 +1,3 @@
+<!--Begin motor PVC9 HTML export from MotorSim-->\r
+<table class='motor'><tr><th colspan='6' class='title'>PVC9</th></tr><tr class='summary'><th>Rating:</th><td>58% G-157</td><th>Total Impulse:</th><td>120 Ns</td><th>Specific Impulse:</th><td>126 s</td></tr><tr class='summary'><th>Max Thrust:</th><td>219 N</td><th>Average Thrust:</th><td>157 N</td><th>Max Pressure:</th><td>3.3 MPa</td></tr><tr><td colspan='6' class='thrust'><img src='http://chart.apis.google.com/chart?chxt=x,x,y,y,r,r&chs=640x240&cht=lxy&chco=3072F3&chds=0,0.86,0,219.04&chxr=0,0,0.86|2,0,219.04|4,0,49.24&chd=t:0,0,0.02,0.06,0.1,0.16,0.25,0.36,0.53,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.71,0.71,0.71,0.76,0.85,0.86|0,55.46,108.17,115.05,124.61,137.84,155.59,178,202.54,219.04,199.1,180.29,162.61,146.03,130.54,116.12,102.76,90.42,79.08,68.72,0.05,0,0&chxl=1:|s|3:|N|5:|lbf&chxp=1,50|3,50|5,50&chtt=Thrust' width='640' height='240' alt='Thrust' /></td></tr></table>
+<!--End motor PVC9-->\r