package math.matrix;

import math.Maths;
import exception.IllegalDimensionException;

/**
 * Second-order tensor (2x2 matrix).
 * @author Daniel Weschke
 */
public class TensorII2D extends Matrix2D {

	/**
	 * UID
	 */
	private static final long serialVersionUID = -3195354821730519791L;

	public TensorII2D() {
		super(2);
	}
	
	public TensorII2D(double a11, double a12, double a21, double a22) {
		super(a11, a12, a21, a22);
	}
	
	public TensorII2D(double[][] a) {
		super(a);
	}

	public TensorII2D(Matrix B) {
		super(B);
	}

	/**
	 * @param ϑ in degrees
	 * @return 2d rotation matrix
	 */
	public static TensorII2D rotation(double ϑ){
        return new TensorII2D(new double[][]{
				{Maths.cosd(ϑ),-Maths.sind(ϑ)},
				{Maths.sind(ϑ), Maths.cosd(ϑ)}});
	}

	public TensorII2D rotate(double ϑ){
		try {
			return (TensorII2D) rotation(ϑ).times(this).times(rotation(ϑ).transpose());
		} catch (IllegalDimensionException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static void main(String[] args) {
		TensorII2D tau = new TensorII2D(1, -1, -1, 1);
		double ϑ = 45;
		tau.rotate(ϑ).println();
	}
}
