JEphem Informatic Trail tig source code Matrix3.java
//*********************************************************************************
// class tig.maths.Matrix3
// Software released under the General Public License (version 2 or later), available at
// http://www.gnu.org/copyleft/gpl.html
//*********************************************************************************

package tig.maths;
/**********************************************************************************
Simple representation of a 3 x 3 matrix based on <CODE>double</CODE>s.
@author Thierry Graff
@history jan 11 2002 : creation
**********************************************************************************/
public class Matrix3{

  //=================================================================================
  //                            CONSTANTS
  //=================================================================================
  /** Term of the matrix */
  public double m00, m01, m02, m10, m11, m12, m20, m21, m22;
					 
  //=================================================================================
  //                            CONSRUCTORS
  //=================================================================================
  /** Unique constructor.
  <BR>Fills the instance variables <CODE>m<SUB>ij</SUB></CODE> from parameters xij.
  */
  public Matrix3(double x00, double x01, double x02, 
                 double x10, double x11, double x12,
                 double x20, double x21, double x22){
    m00 = x00; m01 = x01; m02 = x02;
    m10 = x10; m11 = x11; m12 = x12;
    m20 = x20; m21 = x21; m22 = x22;
  }// end Matrix3


  //=================================================================================
  //                            STATIC METHODS
  //=================================================================================

  //****************** getIdentityMatrix *************************
  /** Returns the identity matrix. */
  public static Matrix3 getIdentityMatrix(){
    return new Matrix3(1, 0, 0,
                       0, 1, 0,
                       0, 0, 1);
  }// end getIdentityMatrix

  //****************** getRotX *************************
  /** Returns a matrix that can be used as a rotation matrix around the X axis. 
  @param alpha The rotation angle, <B>in radians</B>.
  */
  public static Matrix3 getRotX(double alpha){
    double c = Math.cos(alpha);
    double s = Math.sin(alpha);
    return new Matrix3(1,  0, 0,
                        0,  c, s,
                        0, -s, c);
  }// end getRotX

  //****************** getRotY *************************
  /** Returns a matrix that can be used as a rotation matrix around the Y axis.
  @param alpha The rotation angle, <B>in radians</B>.
  */
  public static Matrix3 getRotY(double alpha){
    double c = Math.cos(alpha);
    double s = Math.sin(alpha);
    return new Matrix3(c, 0, -s,
                        0, 1,  0,
                        s, 0,  c);
  }// end getRotY

  //****************** getRotZ *************************
  /** Returns a matrix that can be used as a rotation matrix around the Z axis.
  @param alpha The rotation angle, <B>in radians</B>.
  */
  public static Matrix3 getRotZ(double alpha){
    double c = Math.cos(alpha);
    double s = Math.sin(alpha);
    return new Matrix3( c, s, 0,
                        -s, c, 0,
                         0, 0, 1);
  }// end getRotZ

  //****************** mul *************************
  /** Returns a matrix M such as <B>M = M1 * M2</B>. */
  public static Matrix3 mul(Matrix3 M1, Matrix3 M2){
    return new Matrix3(
                        // first line
                        M1.m00*M2.m00 + M1.m01*M2.m10 + M1.m02*M2.m20 ,
                        M1.m00*M2.m01 + M1.m01*M2.m11 + M1.m02*M2.m21 ,
                        M1.m00*M2.m02 + M1.m01*M2.m12 + M1.m02*M2.m22 ,
                        // second line
                        M1.m10*M2.m00 + M1.m11*M2.m10 + M1.m12*M2.m20 ,
                        M1.m10*M2.m01 + M1.m11*M2.m11 + M1.m12*M2.m21 ,
                        M1.m10*M2.m02 + M1.m11*M2.m12 + M1.m12*M2.m22 ,
                        // third line
                        M1.m20*M2.m00 + M1.m21*M2.m10 + M1.m22*M2.m20 ,
                        M1.m20*M2.m01 + M1.m21*M2.m11 + M1.m22*M2.m21 ,
                        M1.m20*M2.m02 + M1.m21*M2.m12 + M1.m22*M2.m22
                       );
  }// end Matrix3

  //****************** getInverse *************************
  /** Returns the inverse matrix of M.
  <BR>If the resulting matrix is called N, we have : <B>M x N = I</B>, the identity matrix.
  @param M The matrix to invert.
  */
  public static Matrix3 getInverse(Matrix3 M){
    return M;
  }// end getInverse

}//end class Matrix3