Added class with couple of helper methods to compute information about a rocket. Includes getCG and getLength.
This commit is contained in:
parent
edcaa5d2c9
commit
195ad4933b
34
src/net/sf/openrocket/rocketcomponent/RocketUtils.java
Normal file
34
src/net/sf/openrocket/rocketcomponent/RocketUtils.java
Normal file
@ -0,0 +1,34 @@
|
||||
package net.sf.openrocket.rocketcomponent;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.sf.openrocket.masscalc.BasicMassCalculator;
|
||||
import net.sf.openrocket.masscalc.MassCalculator;
|
||||
import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
|
||||
public abstract class RocketUtils {
|
||||
|
||||
public static double getLength(Rocket rocket) {
|
||||
double length = 0;
|
||||
Collection<Coordinate> bounds = rocket.getDefaultConfiguration().getBounds();
|
||||
if (!bounds.isEmpty()) {
|
||||
double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
|
||||
for (Coordinate c : bounds) {
|
||||
if (c.x < minX)
|
||||
minX = c.x;
|
||||
if (c.x > maxX)
|
||||
maxX = c.x;
|
||||
}
|
||||
length = maxX - minX;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
public static Coordinate getCG(Rocket rocket) {
|
||||
MassCalculator massCalculator = new BasicMassCalculator();
|
||||
Coordinate cg = massCalculator.getCG(rocket.getDefaultConfiguration(), MassCalcType.LAUNCH_MASS);
|
||||
return cg;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user