package devUtil;

public class Vector3 {
	
	private double x;
	private double y;
	private double z;
	
	public Vector3() {
		x = 0;
		y = 0;
		z = 0;
	}
	
	public Vector3(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public void setX(double x) {
		this.x = x;
	}
	
	public void setY(double y) {
		this.y = y;
	}
	
	public void setZ(double z) {
		this.z = z;
	}
	
	public double getX() {
		return x;
	}
	
	public double getY() {
		return y;
	}
	
	public double getZ() {
		return z;
	}
	
	public Vector3 getUnitVector() {
		
		return new Vector3(
				x / getMagnitude(),
				y / getMagnitude(),
				z / getMagnitude()
				);
	}
	
	public double getMagnitude() {
		return Math.sqrt((x * x) + (y * y) + (z * z));
	}
	
	public void add(Vector3 foreignVector) {
		x += foreignVector.getX();
		y += foreignVector.getY();
		z += foreignVector.getZ();
	}
	
	public void subtract(Vector3 foreignVector) {
		x -= foreignVector.getX();
		y -= foreignVector.getY();
		z -= foreignVector.getZ();
	}
	
	public double dotProduct(Vector3 foreignVector) {
		
		return 
				x * foreignVector.getX() +
				y * foreignVector.getY() +
				z * foreignVector.getZ();
	}
	
	public Vector3 crossProduct(Vector3 foreignVector) {
		
//		double theta = Math.acos(dotProduct(foreignVector) /
//				(getMagnitude() * foreignVector.getMagnitude())) *
//				(180 / Math.PI);
		
		double cx = y * foreignVector.getZ() - 
				z * foreignVector.getY();
		
		double cy = z * foreignVector.getX() - 
				x * foreignVector.getZ();
		
		double cz = x * foreignVector.getY() - 
				y * foreignVector.getX();
		
		return new Vector3(cx, cy, cz);
	}
}