1 package net.sf.openrocket.gui.rocketfigure;
3 import net.sf.openrocket.rocketcomponent.Transition;
4 import net.sf.openrocket.util.Coordinate;
5 import net.sf.openrocket.util.Transformation;
8 import java.awt.geom.Ellipse2D;
9 import java.awt.geom.Path2D;
10 import java.awt.geom.Rectangle2D;
13 public class TransitionShapes extends RocketComponentShapes {
15 // TODO: LOW: Uses only first component of cluster (not currently clusterable).
17 public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
18 Transformation transformation) {
19 return getShapesSide(component, transformation, S);
22 public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
23 Transformation transformation, final double scaleFactor) {
24 net.sf.openrocket.rocketcomponent.Transition transition = (net.sf.openrocket.rocketcomponent.Transition)component;
28 // Simpler shape for conical transition, others use the method from SymmetricComponent
29 if (transition.getType() == Transition.Shape.CONICAL) {
30 double length = transition.getLength();
31 double r1 = transition.getForeRadius();
32 double r2 = transition.getAftRadius();
33 Coordinate start = transformation.transform(transition.
34 toAbsolute(Coordinate.NUL)[0]);
36 Path2D.Float path = new Path2D.Float();
37 path.moveTo(start.x* scaleFactor, r1* scaleFactor);
38 path.lineTo((start.x+length)* scaleFactor, r2* scaleFactor);
39 path.lineTo((start.x+length)* scaleFactor, -r2* scaleFactor);
40 path.lineTo(start.x* scaleFactor, -r1* scaleFactor);
43 mainShapes = new Shape[] { path };
45 mainShapes = SymmetricComponentShapes.getShapesSide(component, transformation, scaleFactor);
48 Rectangle2D.Double shoulder1=null, shoulder2=null;
49 int arrayLength = mainShapes.length;
51 if (transition.getForeShoulderLength() > 0.0005) {
52 Coordinate start = transformation.transform(transition.
53 toAbsolute(Coordinate.NUL)[0]);
54 double r = transition.getForeShoulderRadius();
55 double l = transition.getForeShoulderLength();
56 shoulder1 = new Rectangle2D.Double((start.x-l)* scaleFactor, -r* scaleFactor, l* scaleFactor, 2*r* scaleFactor);
59 if (transition.getAftShoulderLength() > 0.0005) {
60 Coordinate start = transformation.transform(transition.
61 toAbsolute(new Coordinate(transition.getLength()))[0]);
62 double r = transition.getAftShoulderRadius();
63 double l = transition.getAftShoulderLength();
64 shoulder2 = new Rectangle2D.Double(start.x* scaleFactor, -r* scaleFactor, l* scaleFactor, 2*r* scaleFactor);
67 if (shoulder1==null && shoulder2==null)
70 Shape[] shapes = new Shape[arrayLength];
73 for (i=0; i < mainShapes.length; i++) {
74 shapes[i] = mainShapes[i];
76 if (shoulder1 != null) {
77 shapes[i] = shoulder1;
80 if (shoulder2 != null) {
81 shapes[i] = shoulder2;
87 public static Shape[] getShapesBack(net.sf.openrocket.rocketcomponent.RocketComponent component,
88 Transformation transformation) {
89 net.sf.openrocket.rocketcomponent.Transition transition = (net.sf.openrocket.rocketcomponent.Transition)component;
91 double r1 = transition.getForeRadius();
92 double r2 = transition.getAftRadius();
94 Shape[] s = new Shape[2];
95 s[0] = new Ellipse2D.Double(-r1*S,-r1*S,2*r1*S,2*r1*S);
96 s[1] = new Ellipse2D.Double(-r2*S,-r2*S,2*r2*S,2*r2*S);