Java Matrix Transpose transposeMatrix(final float[] msrc, final int msrc_offset, final float[] mres, final int mres_offset)

Here you can find the source of transposeMatrix(final float[] msrc, final int msrc_offset, final float[] mres, final int mres_offset)

Description

Transpose the given matrix.

License

Open Source License

Parameter

Parameter Description
msrc 4x4 matrix in column-major order, the source
msrc_offset offset in given array <i>msrc</i>, i.e. start of the 4x4 matrix
mres 4x4 matrix in column-major order, the result
mres_offset offset in given array <i>mres</i>, i.e. start of the 4x4 matrix

Return

given result matrix mres for chaining

Declaration

public static float[] transposeMatrix(final float[] msrc,
        final int msrc_offset, final float[] mres, final int mres_offset) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from ww w .ja  v a  2  s.c o m*/
     * Transpose the given matrix.
     *
     * @param msrc 4x4 matrix in column-major order, the source
     * @param msrc_offset offset in given array <i>msrc</i>, i.e. start of the 4x4 matrix
     * @param mres 4x4 matrix in column-major order, the result
     * @param mres_offset offset in given array <i>mres</i>, i.e. start of the 4x4 matrix
     * @return given result matrix <i>mres</i> for chaining
     */
    public static float[] transposeMatrix(final float[] msrc,
            final int msrc_offset, final float[] mres, final int mres_offset) {
        mres[mres_offset + 0] = msrc[msrc_offset + 0 * 4];
        mres[mres_offset + 1] = msrc[msrc_offset + 1 * 4];
        mres[mres_offset + 2] = msrc[msrc_offset + 2 * 4];
        mres[mres_offset + 3] = msrc[msrc_offset + 3 * 4];

        final int i4_1 = 1 * 4;
        mres[mres_offset + 0 + i4_1] = msrc[msrc_offset + 1 + 0 * 4];
        mres[mres_offset + 1 + i4_1] = msrc[msrc_offset + 1 + 1 * 4];
        mres[mres_offset + 2 + i4_1] = msrc[msrc_offset + 1 + 2 * 4];
        mres[mres_offset + 3 + i4_1] = msrc[msrc_offset + 1 + 3 * 4];

        final int i4_2 = 2 * 4;
        mres[mres_offset + 0 + i4_2] = msrc[msrc_offset + 2 + 0 * 4];
        mres[mres_offset + 1 + i4_2] = msrc[msrc_offset + 2 + 1 * 4];
        mres[mres_offset + 2 + i4_2] = msrc[msrc_offset + 2 + 2 * 4];
        mres[mres_offset + 3 + i4_2] = msrc[msrc_offset + 2 + 3 * 4];

        final int i4_3 = 3 * 4;
        mres[mres_offset + 0 + i4_3] = msrc[msrc_offset + 3 + 0 * 4];
        mres[mres_offset + 1 + i4_3] = msrc[msrc_offset + 3 + 1 * 4];
        mres[mres_offset + 2 + i4_3] = msrc[msrc_offset + 3 + 2 * 4];
        mres[mres_offset + 3 + i4_3] = msrc[msrc_offset + 3 + 3 * 4];

        return mres;
    }

    /**
     * Transpose the given matrix.
     *
     * @param msrc 4x4 matrix in column-major order, the source
     * @param mres 4x4 matrix in column-major order, the result
     * @return given result matrix <i>mres</i> for chaining
     */
    public static float[] transposeMatrix(final float[] msrc,
            final float[] mres) {
        mres[0] = msrc[0 * 4];
        mres[1] = msrc[1 * 4];
        mres[2] = msrc[2 * 4];
        mres[3] = msrc[3 * 4];

        final int i4_1 = 1 * 4;
        mres[0 + i4_1] = msrc[1 + 0 * 4];
        mres[1 + i4_1] = msrc[1 + 1 * 4];
        mres[2 + i4_1] = msrc[1 + 2 * 4];
        mres[3 + i4_1] = msrc[1 + 3 * 4];

        final int i4_2 = 2 * 4;
        mres[0 + i4_2] = msrc[2 + 0 * 4];
        mres[1 + i4_2] = msrc[2 + 1 * 4];
        mres[2 + i4_2] = msrc[2 + 2 * 4];
        mres[3 + i4_2] = msrc[2 + 3 * 4];

        final int i4_3 = 3 * 4;
        mres[0 + i4_3] = msrc[3 + 0 * 4];
        mres[1 + i4_3] = msrc[3 + 1 * 4];
        mres[2 + i4_3] = msrc[3 + 2 * 4];
        mres[3 + i4_3] = msrc[3 + 3 * 4];

        return mres;
    }
}

Related

  1. transpose_image(Object source, int width, int height)
  2. transposeBooleanMatrix(boolean[][] matrix)
  3. transposeInPlace(float[] src)
  4. transposeMatrix(double[][] m)
  5. transposeMatrix(double[][] m)
  6. transposeMatrix3x3(float[] result, float[] m)
  7. transposematrixmultiply(final double[][] A, final double[] b)
  8. transposeQuad(final double[][] src, int n)
  9. transposeSquareMatrix(T[][] matrixT)