import java.text.DecimalFormat; 

/**
 * Simple matrix class for COM1370, Summer 2003.
 * 3x3 matrix for homogeneous coordinates in 2D.
 * Produces various matrices via static factory functions.
 *
 * @author Bob Futrelle
 * @version 6/21/2003 (started 6/21/2003)
 */
 
public class HC2DMatrix {

	double[][] matrix;
	
	public static void main(String[] args) {
		HC2DMatrix mat = HC2DMatrix.identity();
		System.out.println(mat);
		System.out.println();
		mat = HC2DMatrix.rotation(Math.PI / 2.0);
		System.out.println(mat);	
		}
	
	HC2DMatrix(){
		double[][] mat = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
		matrix = mat;
		}

	// of course the following could better be done by iteration
	// not by crude typing of every element.
	// Create a result string and simply using '+' will work.
	
	public String toString() {
	
		DecimalFormat fourPlaces = new DecimalFormat( "0.0000");
		
		return fourPlaces.format(matrix[0][0]) + " " + 
			   fourPlaces.format(matrix[0][1])  + " " + 
			   fourPlaces.format(matrix[0][2]) + "\n" +
			   fourPlaces.format(matrix[1][0]) + " " + 
			   fourPlaces.format(matrix[1][1])  + " " + 
			   fourPlaces.format(matrix[1][2]) + "\n" +
			   fourPlaces.format(matrix[2][0]) + " " + 
			   fourPlaces.format(matrix[2][1])  + " " + 
			   fourPlaces.format(matrix[2][2]);
			   
		} // toString()
			
	static HC2DMatrix identity() {
		return new HC2DMatrix();
		}
	
	static HC2DMatrix rotation(double theta) {
		
		HC2DMatrix mat = new HC2DMatrix();
		mat.matrix[0][0] = Math.cos(theta);
		mat.matrix[0][1] = - Math.sin(theta);
		mat.matrix[1][0] = Math.sin(theta);
		mat.matrix[1][1] = Math.cos(theta);
		
		return mat;
	
		}
} // class Transforms

