1 package net.sf.openrocket.rocketcomponent;
3 import java.util.ArrayList;
4 import java.util.Collections;
9 * Class that defines different cluster configurations available for the InnerTube.
10 * The class is immutable, and all the constructors are private. Therefore the only
11 * available cluster configurations are those available in the static fields.
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public class ClusterConfiguration {
17 private static final double R5 = 1.0/(2*Math.sin(2*Math.PI/10));
18 private static final double SQRT2 = Math.sqrt(2);
19 private static final double SQRT3 = Math.sqrt(3);
22 public static final ClusterConfiguration SINGLE = new ClusterConfiguration("single", 0,0);
24 /** Definitions of cluster configurations. Do not modify array. */
25 public static final ClusterConfiguration[] CONFIGURATIONS = {
28 new ClusterConfiguration("double", -0.5,0, 0.5,0),
29 new ClusterConfiguration("3-row", -1.0,0, 0.0,0, 1.0,0),
30 new ClusterConfiguration("4-row", -1.5,0, -0.5,0, 0.5,0, 1.5,0),
33 new ClusterConfiguration("3-ring", -0.5,-1.0/(2*SQRT3),
36 new ClusterConfiguration("4-ring", -0.5,0.5, 0.5,0.5, 0.5,-0.5, -0.5,-0.5),
37 new ClusterConfiguration("5-ring", 0,R5,
38 R5*Math.sin(2*Math.PI/5),R5*Math.cos(2*Math.PI/5),
39 R5*Math.sin(2*Math.PI*2/5),R5*Math.cos(2*Math.PI*2/5),
40 R5*Math.sin(2*Math.PI*3/5),R5*Math.cos(2*Math.PI*3/5),
41 R5*Math.sin(2*Math.PI*4/5),R5*Math.cos(2*Math.PI*4/5)),
42 new ClusterConfiguration("6-ring", 0,1, SQRT3/2,0.5, SQRT3/2,-0.5,
43 0,-1, -SQRT3/2,-0.5, -SQRT3/2,0.5),
46 new ClusterConfiguration("3-star", 0,0, 0,1, SQRT3/2,-0.5, -SQRT3/2,-0.5),
47 new ClusterConfiguration("4-star", 0,0, -1/SQRT2,1/SQRT2, 1/SQRT2,1/SQRT2,
48 1/SQRT2,-1/SQRT2, -1/SQRT2,-1/SQRT2),
49 new ClusterConfiguration("5-star", 0,0, 0,1,
50 Math.sin(2*Math.PI/5),Math.cos(2*Math.PI/5),
51 Math.sin(2*Math.PI*2/5),Math.cos(2*Math.PI*2/5),
52 Math.sin(2*Math.PI*3/5),Math.cos(2*Math.PI*3/5),
53 Math.sin(2*Math.PI*4/5),Math.cos(2*Math.PI*4/5)),
54 new ClusterConfiguration("6-star", 0,0, 0,1, SQRT3/2,0.5, SQRT3/2,-0.5,
55 0,-1, -SQRT3/2,-0.5, -SQRT3/2,0.5)
59 private final List<Double> points;
60 private final String xmlName;
62 private ClusterConfiguration(String xmlName, double... points) {
63 this.xmlName = xmlName;
64 if (points.length == 0 || points.length%2 == 1) {
65 throw new IllegalArgumentException("Illegal number of points specified: "+
68 List<Double> l = new ArrayList<Double>(points.length);
69 for (double d: points)
72 this.points = Collections.unmodifiableList(l);
75 public String getXMLName() {
79 public int getClusterCount() {
80 return points.size()/2;
83 public List<Double> getPoints() {
84 return points; // Unmodifiable
88 * Return the points rotated by <code>rotation</code> radians.
89 * @param rotation Rotation amount.
91 public List<Double> getPoints(double rotation) {
92 double cos = Math.cos(rotation);
93 double sin = Math.sin(rotation);
94 List<Double> ret = new ArrayList<Double>(points.size());
95 for (int i=0; i<points.size()/2; i++) {
96 double x = points.get(2*i);
97 double y = points.get(2*i+1);
98 ret.add( x*cos + y*sin);
99 ret.add(-x*sin + y*cos);