]> git.gag.com Git - sw/motorsim/blob - src/com/billkuker/rocketry/motorsim/grain/Star.java
Regenerate multiport geometry
[sw/motorsim] / src / com / billkuker / rocketry / motorsim / grain / Star.java
1 package com.billkuker.rocketry.motorsim.grain;\r
2 \r
3 import java.awt.Shape;\r
4 import java.awt.geom.Area;\r
5 import java.awt.geom.Ellipse2D;\r
6 import java.awt.geom.GeneralPath;\r
7 import java.beans.PropertyVetoException;\r
8 \r
9 import javax.measure.quantity.Length;\r
10 import javax.measure.unit.SI;\r
11 \r
12 import org.jscience.physics.amount.Amount;\r
13 \r
14 import com.billkuker.rocketry.motorsim.Validating;\r
15 import com.billkuker.rocketry.motorsim.grain.util.BurningShape;\r
16 import com.billkuker.rocketry.motorsim.grain.util.ExtrudedShapeGrain;\r
17 \r
18 public class Star extends ExtrudedShapeGrain implements Validating {\r
19         private Amount<Length> oD = Amount.valueOf(30, SI.MILLIMETER);\r
20         private Amount<Length> iD = Amount.valueOf(5, SI.MILLIMETER);\r
21         private Amount<Length> pD = Amount.valueOf(15, SI.MILLIMETER);\r
22         private int pointCount = 5;\r
23         \r
24         public Star(){\r
25                 try {\r
26                         setLength(Amount.valueOf(70, SI.MILLIMETER));\r
27                 } catch (PropertyVetoException e) {\r
28                         e.printStackTrace();\r
29                 }\r
30                 generateGeometry();\r
31         }\r
32         \r
33         private void generateGeometry(){\r
34                 double odmm = oD.doubleValue(SI.MILLIMETER);\r
35                 double idmm = iD.doubleValue(SI.MILLIMETER)/2.0;\r
36                 double pdmm = pD.doubleValue(SI.MILLIMETER)/2.0;\r
37                 \r
38                 xsection = new BurningShape();\r
39                 Shape outside = new Ellipse2D.Double(-odmm/2, -odmm/2, odmm, odmm);\r
40                 xsection.add(outside);\r
41                 xsection.inhibit(outside);\r
42                 //xsection.subtract(new Ellipse2D.Double(-idmm/2, -idmm/2, idmm, idmm));\r
43                 webThickness = null;\r
44                 \r
45                 GeneralPath p = new GeneralPath();\r
46                 double theta = 0;\r
47                 double dTheta = (2.0 * Math.PI) / ( pointCount * 2.0 );\r
48                 p.moveTo(0, idmm);\r
49                 for ( int i = 0; i < pointCount; i++ ){\r
50                         theta += dTheta;\r
51                         p.lineTo(pdmm*Math.sin(theta), pdmm*Math.cos(theta));\r
52                         theta += dTheta;\r
53                         p.lineTo(idmm*Math.sin(theta), idmm*Math.cos(theta));\r
54                 }\r
55                 p.closePath();\r
56                 xsection.subtract(new Area(p));\r
57         }\r
58         \r
59         public Amount<Length> getOD() {\r
60                 return oD;\r
61         }\r
62 \r
63         public void setOD(Amount<Length> od) throws PropertyVetoException {\r
64                 if (od.equals(this.oD))\r
65                         return;\r
66                 this.oD = od;\r
67                 generateGeometry();\r
68         }\r
69 \r
70         public Amount<Length> getID() {\r
71                 return iD;\r
72         }\r
73 \r
74         public void setID(Amount<Length> id) throws PropertyVetoException {\r
75                 if (id.equals(this.iD))\r
76                         return;\r
77                 iD = id;\r
78                 generateGeometry();\r
79         }\r
80         \r
81         public Amount<Length> getPointDiameter() {\r
82                 return pD;\r
83         }\r
84 \r
85         public void setPointDiameter(Amount<Length> pd) throws PropertyVetoException {\r
86                 if (pd.equals(this.pD))\r
87                         return;\r
88                 pD = pd;\r
89                 generateGeometry();\r
90         }\r
91         \r
92         public int getPointCount(){\r
93                 return pointCount;\r
94         }\r
95         \r
96         public void setPointCount(final int points) throws PropertyVetoException{\r
97                 if ( points < 2 || points > 8 )\r
98                         throw new PropertyVetoException("Invalid number of points", null);\r
99                 pointCount = points;\r
100                 generateGeometry();\r
101         }\r
102         \r
103         @Override\r
104         public void validate() throws ValidationException{\r
105                 if ( iD.equals(Amount.ZERO) )\r
106                         throw new ValidationException(this, "Invalid iD");\r
107                 if ( oD.equals(Amount.ZERO) )\r
108                         throw new ValidationException(this, "Invalid oD");\r
109                 if ( getLength().equals(Amount.ZERO) )\r
110                         throw new ValidationException(this, "Invalid Length");\r
111                 if ( iD.isGreaterThan(oD) )\r
112                         throw new ValidationException(this, "iD > oD");         \r
113                 if ( iD.isGreaterThan(pD) )\r
114                         throw new ValidationException(this, "iD > pD");         \r
115                 if ( pD.isGreaterThan(oD) )\r
116                         throw new ValidationException(this, "pD > oD"); \r
117         }\r
118 }\r