<html>  <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>import java</title> </head>  <body>  <p><br> import java.lang.Math;<br> <br> class Matrix_4X4<br> {<br>  double[][] Matrix = new double[4][4];<br> <br>  public void identity()<br>  {for(int j = 0; j &lt; 4; j++)&nbsp;<br> 	{	for(int k = 0; k &lt; 4; k++)&nbsp;<br> 	 	 {if (j != k) Matrix[j][k] = 0;<br> 	  	  else Matrix[j][k] = 1;&nbsp;<br> 	 	 }<br> 	}<br> <br>  }&nbsp;<br>  //<br>  public void preMultiply(Matrix_4X4 mat)<br>  { for(int i = 0; i &lt; 4; i++)<br>    {for(int j = 0; j &lt; 4; j++)<br>     {Matrix[i][j] = ( (Matrix[0][j] * mat.Matrix[i][0]) +<br>     				  (Matrix[1][j] * mat.Matrix[i][1]) +<br>     				  (Matrix[2][j] * mat.Matrix[i][2]) +<br>     				  (Matrix[3][j] * mat.Matrix[i][3]) );<br>     }<br>    }<br>  }<br> <br>  public void postMultiply(Matrix_4X4 mat)<br>  { for(int i = 0; i &lt; 4; i++)<br>    {for(int j = 0; j &lt; 4; j++)<br>     {Matrix[i][j] = ( (mat.Matrix[0][j] * Matrix[i][0]) +<br>     				  (mat.Matrix[1][j] * Matrix[i][1]) +<br>     				  (mat.Matrix[2][j] * Matrix[i][2]) +<br>     				  (mat.Matrix[3][j] * Matrix[i][3]) );<br>     }<br>    }<br>  }<br> <br>  public void translate(double tx, double ty, double tz)<br>  {//create new matrix<br>   Matrix_4X4 tmp = new Matrix_4X4();<br>   tmp.identity();&nbsp;<br>   tmp.Matrix[3][0] = tx;<br>   tmp.Matrix[3][1] = ty;<br>   tmp.Matrix[3][2] = tz;<br>   postMultiply(tmp);<br>  }<br> <br>  public void rotateX(double theta)<br>  {Matrix_4X4 tmp = new Matrix_4X4();<br>   tmp.identity();&nbsp;<br>   tmp.Matrix[1][1] = (double)Math.cos((theta * Math.PI/180.0));<br>   tmp.Matrix[2][1] = (-1 * ((double)Math.sin((theta * Math.PI/180.0))));<br>   tmp.Matrix[1][2] = (double)Math.sin((theta * Math.PI/180.0));<br>   tmp.Matrix[2][2] = (double)Math.cos((theta * Math.PI/180.0));<br>   postMultiply(tmp);<br>  }<br> <br>  public void rotateY(double theta)<br>  {Matrix_4X4 tmp = new Matrix_4X4();<br>   tmp.identity();&nbsp;<br>   tmp.Matrix[0][0] = (double)Math.cos((theta * Math.PI/180.0));<br>   tmp.Matrix[0][2] = (-1 * ((double)Math.sin((theta * Math.PI/180.0))));<br>   tmp.Matrix[2][0] = (double)Math.sin((theta * Math.PI/180.0));<br>   tmp.Matrix[2][2] = (double)Math.cos((theta * Math.PI/180.0));<br>   postMultiply(tmp);<br>  }<br> <br>  public void rotateZ(double theta)<br>  {Matrix_4X4 tmp = new Matrix_4X4();<br>   tmp.identity();&nbsp;<br>   tmp.Matrix[0][0] = (double)Math.cos((theta * Math.PI/180.0));<br>   tmp.Matrix[1][0] = (-1 * ((double)Math.sin((theta * Math.PI/180.0))));<br>   tmp.Matrix[0][1] = (double)Math.sin((theta * Math.PI/180.0));<br>   tmp.Matrix[1][1] = (double)Math.cos((theta * Math.PI/180.0));<br>   postMultiply(tmp);<br>  }<br> <br>  public void scale(double sx, double sy, double sz)<br>  {Matrix_4X4 tmp = new Matrix_4X4();<br>   tmp.identity();<br>   tmp.Matrix[0][0] = sx;<br>   tmp.Matrix[1][1] = sy;<br>   tmp.Matrix[2][2] = sz;<br>   postMultiply(tmp);<br>  }<br> <br>  public double transformX(double x, double y, double z)&nbsp;<br>  {double newX = ( (Matrix[0][0] * x) + (Matrix[1][0] * y) + (Matrix[2][0] * z) + (Matrix[3][0]) );<br>   return newX;&nbsp;<br>  }<br> <br>  public double transformY(double x, double y, double z)<br>  {double newY = ( (Matrix[0][1] * x) + (Matrix[1][1] * y) + (Matrix[2][1] * z) + (Matrix[3][1]) );<br>   return newY;<br>  }<br> <br>  public double transformZ(double x, double y, double z)<br>  {double newZ = ( (Matrix[0][2] * x) + (Matrix[1][2] * y) + (Matrix[2][2] * z) + (Matrix[3][2]) );<br>   return newZ;<br>  }<br> }<br> </p>  </body>  </html> 
