Java Matrix Invert invert(float[] mat)

Here you can find the source of invert(float[] mat)

Description

invert

License

Open Source License

Declaration

public static void invert(float[] mat) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void invert(float[] mat) {
        float dx = -mat[3];
        float dy = -mat[7];
        float dz = -mat[11];
        invert3x3(mat);//from ww  w .j ava  2 s  .co m

        mat[3] = mat[0] * dx + mat[1] * dy + mat[2] * dz;
        mat[7] = mat[4] * dx + mat[5] * dy + mat[6] * dz;
        mat[11] = mat[8] * dx + mat[9] * dy + mat[10] * dz;
    }

    public static void invert3x3(float[] mat) {
        double sub00 = mat[5] * mat[10] - mat[6] * mat[9];
        double sub01 = mat[4] * mat[10] - mat[6] * mat[8];
        double sub02 = mat[4] * mat[9] - mat[5] * mat[8];
        double sub10 = mat[1] * mat[10] - mat[2] * mat[9];
        double sub11 = mat[0] * mat[10] - mat[2] * mat[8];
        double sub12 = mat[0] * mat[9] - mat[1] * mat[8];
        double sub20 = mat[1] * mat[6] - mat[2] * mat[5];
        double sub21 = mat[0] * mat[6] - mat[2] * mat[4];
        double sub22 = mat[0] * mat[5] - mat[1] * mat[4];
        double det = mat[0] * sub00 - mat[1] * sub01 + mat[2] * sub02;

        mat[0] = (float) (sub00 / det);
        mat[1] = -(float) (sub10 / det);
        mat[2] = (float) (sub20 / det);
        mat[4] = -(float) (sub01 / det);
        mat[5] = (float) (sub11 / det);
        mat[6] = -(float) (sub21 / det);
        mat[8] = (float) (sub02 / det);
        mat[9] = -(float) (sub12 / det);
        mat[10] = (float) (sub22 / det);
    }
}

Related

  1. invert(double a[][])
  2. invert(final int[][] input)
  3. invert2x2(final double[][] src, final double[][] dest)
  4. invert3x3(float[] mat)
  5. invert44Matrix(final double[] m, final double[] invOut)
  6. invertDataSet(double[][] dataSet)