1 package net.sf.openrocket.simulation;
3 import net.sf.openrocket.util.Coordinate;
4 import net.sf.openrocket.util.MathUtil;
7 * An immutable value object containing the mass data of a rocket.
9 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
11 public class MassData {
13 private final Coordinate cg;
14 private final double longitudalInertia;
15 private final double rotationalInertia;
18 public MassData(Coordinate cg, double longitudalInertia, double rotationalInertia) {
20 throw new IllegalArgumentException("cg is null");
23 this.longitudalInertia = longitudalInertia;
24 this.rotationalInertia = rotationalInertia;
30 public Coordinate getCG() {
34 public double getLongitudalInertia() {
35 return longitudalInertia;
38 public double getRotationalInertia() {
39 return rotationalInertia;
45 public boolean equals(Object obj) {
48 if (!(obj instanceof MassData))
51 MassData other = (MassData) obj;
52 return (this.cg.equals(other.cg) && MathUtil.equals(this.longitudalInertia, other.longitudalInertia) &&
53 MathUtil.equals(this.rotationalInertia, other.rotationalInertia));
58 public int hashCode() {
59 return (int) (cg.hashCode() ^ Double.doubleToLongBits(longitudalInertia) ^ Double.doubleToLongBits(rotationalInertia));
64 public String toString() {
65 return "MassData [cg=" + cg + ", longitudalInertia=" + longitudalInertia
66 + ", rotationalInertia=" + rotationalInertia + "]";