protected static boolean invert(double[] src,double[] dst){
  double[][] A=new double[4][4];
  A[0][0]=src[0];
  A[0][1]=src[1];
  A[0][2]=src[2];
  A[0][3]=src[3];
  A[1][0]=src[4];
  A[1][1]=src[5];
  A[1][2]=src[6];
  A[1][3]=src[7];
  A[2][0]=src[8];
  A[2][1]=src[9];
  A[2][2]=src[10];
  A[2][3]=src[11];
  A[3][0]=src[12];
  A[3][1]=src[13];
  A[3][2]=src[14];
  A[3][3]=src[15];
  int[] index=new int[4];
  double d=ludcmp(A,index);
  for (int i=0; i < 4; i+=1) {
    d*=A[i][i];
  }
  final double NEAR_ZERO_THRESHOLD=1.0e-8;
  if (Math.abs(d) < NEAR_ZERO_THRESHOLD) {
    return false;
  }
  double[][] Y=new double[4][4];
  double[] col=new double[4];
  for (int j=0; j < 4; j+=1) {
    for (int i=0; i < 4; i+=1) {
      col[i]=0.0;
    }
    col[j]=1.0;
    lubksb(A,index,col);
    for (int i=0; i < 4; i+=1) {
      Y[i][j]=col[i];
    }
  }
  dst[0]=Y[0][0];
  dst[1]=Y[0][1];
  dst[2]=Y[0][2];
  dst[3]=Y[0][3];
  dst[4]=Y[1][0];
  dst[5]=Y[1][1];
  dst[6]=Y[1][2];
  dst[7]=Y[1][3];
  dst[8]=Y[2][0];
  dst[9]=Y[2][1];
  dst[10]=Y[2][2];
  dst[11]=Y[2][3];
  dst[12]=Y[3][0];
  dst[13]=Y[3][1];
  dst[14]=Y[3][2];
  dst[15]=Y[3][3];
  return true;
}

protected static boolean invert ( double [ ] src , double [ ] dst ) { double [ ] [ ] A = new double [ 4 ] [ 4 ] ; A [ 0 ] [ 0 ] = src [ 0 ] ; A [ 0 ] [ 1 ] = src [ 1 ] ; A [ 0 ] [ 2 ] = src [ 2 ] ; A [ 0 ] [ 3 ] = src [ 3 ] ; A [ 1 ] [ 0 ] = src [ 4 ] ; A [ 1 ] [ 1 ] = src [ 5 ] ; A [ 1 ] [ 2 ] = src [ 6 ] ; A [ 1 ] [ 3 ] = src [ 7 ] ; A [ 2 ] [ 0 ] = src [ 8 ] ; A [ 2 ] [ 1 ] = src [ 9 ] ; A [ 2 ] [ 2 ] = src [ 10 ] ; A [ 2 ] [ 3 ] = src [ 11 ] ; A [ 3 ] [ 0 ] = src [ 12 ] ; A [ 3 ] [ 1 ] = src [ 13 ] ; A [ 3 ] [ 2 ] = src [ 14 ] ; A [ 3 ] [ 3 ] = src [ 15 ] ; int [ ] index = new int [ 4 ] ; double d = ludcmp ( A , index ) ; for ( int i = 0 ; i < 4 ; i += 1 ) { d *= A [ i ] [ i ] ; } final double NEAR_ZERO_THRESHOLD = 1.0e-8 ; if ( Math . abs ( d ) < NEAR_ZERO_THRESHOLD ) { return false ; } double [ ] [ ] Y = new double [ 4 ] [ 4 ] ; double [ ] col = new double [ 4 ] ; for ( int j = 0 ; j < 4 ; j += 1 ) { for ( int i = 0 ; i < 4 ; i += 1 ) { col [ i ] = 0.0 ; } col [ j ] = 1.0 ; lubksb ( A , index , col ) ; for ( int i = 0 ; i < 4 ; i += 1 ) { Y [ i ] [ j ] = col [ i ] ; } } dst [ 0 ] = Y [ 0 ] [ 0 ] ; dst [ 1 ] = Y [ 0 ] [ 1 ] ; dst [ 2 ] = Y [ 0 ] [ 2 ] ; dst [ 3 ] = Y [ 0 ] [ 3 ] ; dst [ 4 ] = Y [ 1 ] [ 0 ] ; dst [ 5 ] = Y [ 1 ] [ 1 ] ; dst [ 6 ] = Y [ 1 ] [ 2 ] ; dst [ 7 ] = Y [ 1 ] [ 3 ] ; dst [ 8 ] = Y [ 2 ] [ 0 ] ; dst [ 9 ] = Y [ 2 ] [ 1 ] ; dst [ 10 ] = Y [ 2 ] [ 2 ] ; dst [ 11 ] = Y [ 2 ] [ 3 ] ; dst [ 12 ] = Y [ 3 ] [ 0 ] ; dst [ 13 ] = Y [ 3 ] [ 1 ] ; dst [ 14 ] = Y [ 3 ] [ 2 ] ; dst [ 15 ] = Y [ 3 ] [ 3 ] ; return true ; }
inverts a 4 x 4 matrix , storing the result in a destination argument . the source and destination arguments represent a 4 x 4 matrix with a one - dimensional array in row - major order . the source and destination may reference the same array .
