import java.awt.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Matrix
{
	public float Mat[][] = new float[4][4];
	
	
	Matrix()
	{
	}
	
	public void Initialize()
	{
		for(int i = 0;i < 4;i ++)
		{
			for(int j = 0;j < 4;j ++)
			{
				if(i != j)
				{
					Mat[i][j] = 0;
				}
				else
				{
					Mat[i][j] = 1;
				}
			}
		}
	}
	
	public Matrix Mul(Matrix M)
	{
		Matrix T = new Matrix ();
		for(int i = 0;i < 4;i ++)
		{
			for(int j = 0;j < 4;j ++)
			{
				T.Mat[i][j] = 0;
				for(int k = 0;k < 4;k ++)
				{
					T.Mat[i][j] += Mat[i][k] * M.Mat[k][j];
				}
			}
		}
		return T;
	}
	
	/*
	Values for axis
	X = 0
	Y = 1
	Z = 2
	*/
	
	public void setRotate(float angle,int axis)
	{
		int x = (axis + 1)%3;
		int y = (axis + 2)%3;
		Mat[x][x] = (float)Math.cos(angle);
		Mat[x][y] = -1 * (float)Math.sin(angle);
		Mat[y][x] = (float)Math.sin(angle);
		Mat[y][y] = (float)Math.cos(angle);
	}
	
	public void setTranslate(float x,float y,float z)
	{
		Mat[0][3] = x;
		Mat[1][3] = y;
		Mat[2][3] = z;
	}
	
	public void setScale(float x,float y,float z)
	{
		Mat[0][0] = x;
		Mat[1][1] = y;
		Mat[2][2] = z;
	}
	
	public void Print()
	{
		System.out.println(Mat[0][0]);
		System.out.println(Mat[0][1]);
		System.out.println(Mat[1][0]);
		System.out.println(Mat[1][1]);
	}
}

class Transform
{
	Matrix M = new Matrix ();
	float xx;
	float yy;
	float zz;
	
	void Print()
	{
		M.Print();
	}
	void Transform()
	{
		M.Initialize();
	}
	
	public void Initialize()
	{
		M.Initialize();
	}
	public void rotateZ(float angle)
	{
		Matrix M1 = new Matrix();
		M1.Initialize();
		M1.setRotate(angle,2);
		M = M1.Mul(M);
	}
	
	public void rotateX(float angle)
	{
		Matrix M1 = new Matrix();
		M1.Initialize();
		M1.setRotate(angle,0);
		M = M1.Mul(M);
	}
	
	public void rotateY(float angle)
	{
		Matrix M1 = new Matrix();
		M1.Initialize();
		M1.setRotate(angle,1);
		M = M1.Mul(M);
	}
	
	public void Scale(float x,float y,float z)
	{
		Matrix M1 = new Matrix();
		M1.Initialize();
		M1.setScale(x,y,z);
		M = M1.Mul(M);
	}
	
	public void Translate(float x,float y,float z)
	{
		Matrix M1 = new Matrix();
		M1.Initialize();
		M1.setTranslate(x,y,z);
		M = M1.Mul(M);
	}
	
	public void transformPt(float x,float y,float z)
	{
		float Arr [] = new float [4];
		Arr[0] = x;
		Arr[1] = y;
		Arr[2] = z;
		Arr[3] = 1;
		float Ans [] = new float [4];
		for(int i = 0;i < 4;i ++)
		{
			Ans[i] = 0;
			for(int j = 0;j < 1;j ++)
			{
				for(int k = 0;k < 4;k ++)
				{
					Ans[i] += M.Mat[i][k] * Arr[k];
				}
			}
		}
		xx = Ans[0];
		yy = Ans[1];
		zz = Ans[2];
	}
	
	public float getX()
	{
		return xx;
	}
	
	public float getY()
	{
		return yy;
	}
	
	public float getZ()
	{
		return zz;
	}
}

