public class Vector3D {
	private double vec_[] = new double[3];
	static private Vector3D temp_ = new Vector3D();
	
	Vector3D(double x, double y, double z) {
		vec_[0] = x;
		vec_[1] = y;
		vec_[2] = z;
	}
	Vector3D() {
		this(.0,0.,.0);
	}
	double[] vector() {
		return vec_;
	}
	double get(int i) {
		return vec_[i];
	}
	double set(int i, double v) {
		return vec_[i] = v;
	}
	double x() {
		return vec_[0];
	}
	double y() {
		return vec_[1];
	}
	double z() {
		return vec_[2];
	}
	Vector3D copy(Vector3D other) {
		for(int i = 0; i<3; ++i) 
			vec_[i] = other.vec_[i];
		return this;
	}
	Vector3D reverse() {
		for(int i = 0; i<3; ++i) 
			vec_[i] = -vec_[i];
		return this;
	}
	Vector3D add(Vector3D other, Vector3D out) {
		for(int i = 0; i<3; ++i) 
			out.vec_[i] = vec_[i] + other.vec_[i];
		return out;
	}
	Vector3D add(Vector3D other) {
		temp_.copy(this);
		return temp_.add(other,this);
	}
	Vector3D subtract(Vector3D other, Vector3D out) {
		for(int i = 0; i<3; ++i) 
			out.vec_[i] = vec_[i] - other.vec_[i];
		return out;
	}
	Vector3D subtract(Vector3D other) {
		temp_.copy(this);
		return temp_.subtract(other,this);
	}
}