package net.willware.Orbits;

/**
 * Created by IntelliJ IDEA.
 * User: wware
 * Date: Oct 16, 2004
 * Time: 8:50:59 AM
 */
public class Vector {
	private final static boolean SANITY_CHECKING = true;
	private double x, y, z;
	private void sanity(double x, String name) {
		if (x * x > 1.0e60)
			throw new RuntimeException(name + " too big");
	}
	public Vector(double x, double y, double z) {
		if (SANITY_CHECKING) {
			sanity(x, "x");
			sanity(y, "y");
			sanity(z, "z");
		}
		this.x = x;
		this.y = y;
		this.z = z;
	}
	public Vector() {
		this.x = 0.0;
		this.y = 0.0;
		this.z = 0.0;
	}
	public String toString() {
		return "{" + x + ", " + y + ", " + z + "}";
	}
	public double getX() { return x; }
	public double getY() { return y; }
	public double getZ() { return z; }
	public Vector scale(double m) {
		if (SANITY_CHECKING) sanity(m, "scale factor");
		return new Vector(m * x, m * y, m * z);
	}
	public Vector add(Vector other) {
		return new Vector(x + other.x, y + other.y, z + other.z);
	}
	public Vector subtract(Vector other) {
		return new Vector(x - other.x, y - other.y, z - other.z);
	}
	public double length() {
		return Math.sqrt(x * x + y * y + z * z);
	}
}
