package math.matrix;

import exception.IllegalDimensionException;

/**
 * 2D vector of real numbers, v<sub>i</sub>&isin;&#x211D;.
 * @author Daniel Weschke
 */
public class Vector2D extends Vector{
	
	/**
	 * UID
	 */
	private static final long serialVersionUID = -4752129361019389194L;
	
	public Vector2D(){
		super(2);
	}

	/**
	 * Create vector with given x and y value
	 * @param x
	 * @param y
	 */
	public Vector2D(double x, double y){
		super(x,y);
	}

	/**
	 * Create vector with given array
	 * @param data array
	 */
	public Vector2D(double... data){
		super(data);
	}
	
	/**
	 * Copy vector
	 * @param v vector
	 */
	public Vector2D(Vector v){
		super(v);
	}
	
	/**
	 * revolve vector 90°. max 2 dimension vector.
	 * @return 90° revolved vector
	 */
	public Vector2D orthogonal(){
		return new Vector2D(get(1),get(0));
	}
	
	/**
	 * revolve normalized vector 90°.
	 * @return 90° revolved normalized vector
	 */
	public Vector2D orthonormalized(){
		return (Vector2D) orthogonal().normalize();
	}
	
	/**
	 * lengthen the vector and revolve 90°.
	 * @param a lengthen factor
	 * @return 90° revolved lengthened vector
	 */
	public Vector2D orthogonalScalarMultiplication(Double a){
		return (Vector2D) orthonormalized().times(a);
	}

	/**
	 * Rotation by ϑ degrees counterclockwise or -ϑ degrees clockwise.
	 * @param ϑ in degrees
	 * @return rotated vector
	 * @throws IllegalDimensionException
	 */
	public Vector2D rotate(double ϑ) throws IllegalDimensionException{
		if(!isR2()) throw new IllegalDimensionException("Illegal vector dimensions.");
		return (Vector2D) TensorII2D.rotation(ϑ).times(this);
	}

	public static void main(String[] args) {
	}

}
