+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