float Determinant(  // 40 mul 23 add
    float m00, float m01, float m02, float m03,
    float m10, float m11, float m12, float m13,
    float m20, float m21, float m22, float m23,
    float m30, float m31, float m32, float m33
) {
    return
        m00 * Determinant3(
            m11, m12, m13,
            m21, m22, m23,
            m31, m32, m33
        )
      + m10 * Determinant3(
            m21, m22, m23,
            m31, m32, m33,
            m01, m02, m03
        )
      + m20 * Determinant3(
            m31, m32, m33,
            m01, m02, m03,
            m11, m12, m13
        )
      + m30 * Determinant3(
            m01, m02, m03,
            m11, m12, m13,
            m21, m22, m23
        );
}
Пример #2
0
float hsMatrix44::GetDeterminant() const
{
    return (fMap[0][0]*Determinant3(fMap[1][1], fMap[2][1], fMap[3][1],
                                      fMap[1][2], fMap[2][2], fMap[3][2],
                                      fMap[1][3], fMap[2][3], fMap[3][3]) - 
            fMap[1][0]*Determinant3(fMap[0][1], fMap[2][1], fMap[3][1],
                                      fMap[0][2], fMap[2][2], fMap[3][2],
                                      fMap[0][3], fMap[2][3], fMap[3][3]) +
            fMap[2][0]*Determinant3(fMap[0][1], fMap[1][1], fMap[3][1],
                                      fMap[0][2], fMap[1][2], fMap[3][2],
                                      fMap[0][3], fMap[1][3], fMap[3][3]) -
            fMap[3][0]*Determinant3(fMap[0][1], fMap[1][1], fMap[2][1],
                                      fMap[0][2], fMap[1][2], fMap[2][2],
                                      fMap[0][3], fMap[1][3], fMap[2][3]));
}
Пример #3
0
void TTetrahedron::ComputeVolume() {
    double a[ 3 ][ 3 ];

    a[ 0 ][ 0 ] = X2.X() - X1.X();
    a[ 0 ][ 1 ] = X2.Y() - X1.Y();
    a[ 0 ][ 2 ] = X2.Z() - X1.Z();
    a[ 1 ][ 0 ] = X3.X() - X1.X();
    a[ 1 ][ 1 ] = X3.Y() - X1.Y();
    a[ 1 ][ 2 ] = X3.Z() - X1.Z();
    a[ 2 ][ 0 ] = X4.X() - X1.X();
    a[ 2 ][ 1 ] = X4.Y() - X1.Y();
    a[ 2 ][ 2 ] = X4.Z() - X1.Z();

    volume = fabs(Determinant3(a)) / 6.0;
}
Пример #4
0
hsMatrix44 *hsMatrix44::GetAdjoint(hsMatrix44 *adj) const
{
    float   a1, a2, a3, a4, b1, b2, b3, b4;
    float   c1, c2, c3, c4, d1, d2, d3, d4;
/*
 *     calculate the adjoint of a 4x4 matrix
 *
 *      Let  a   denote the minor determinant of matrix A obtained by
 *           ij
 *
 *      deleting the ith row and jth column from A.
 *
 *                    i+j
 *     Let  b   = (-1)    a
 *          ij            ji
 *
 *    The matrix B = (b  ) is the adjoint of A
 *                     ij
 */

    /* assign to individual variable names to aid  */
    /* selecting correct values  */

    a1 = fMap[0][0];
    b1 = fMap[0][1];
    c1 = fMap[0][2];
    d1 = fMap[0][3];

    a2 = fMap[1][0];
    b2 = fMap[1][1];
    c2 = fMap[1][2];
    d2 = fMap[1][3];

    a3 = fMap[2][0];
    b3 = fMap[2][1];
    c3 = fMap[2][2];
    d3 = fMap[2][3];

    a4 = fMap[3][0];
    b4 = fMap[3][1];
    c4 = fMap[3][2];
    d4 = fMap[3][3];

    /*
     * row column labeling reversed since we transpose rows & columns
     */

    adj->fMap[0][0] = Determinant3(b2, b3, b4, c2, c3, c4, d2, d3, d4);
    adj->fMap[1][0] = -Determinant3(a2, a3, a4, c2, c3, c4, d2, d3, d4);
    adj->fMap[2][0] = Determinant3(a2, a3, a4, b2, b3, b4, d2, d3, d4);
    adj->fMap[3][0] = -Determinant3(a2, a3, a4, b2, b3, b4, c2, c3, c4);

    adj->fMap[0][1] = -Determinant3(b1, b3, b4, c1, c3, c4, d1, d3, d4);
    adj->fMap[1][1] = Determinant3(a1, a3, a4, c1, c3, c4, d1, d3, d4);
    adj->fMap[2][1] = -Determinant3(a1, a3, a4, b1, b3, b4, d1, d3, d4);
    adj->fMap[3][1] = Determinant3(a1, a3, a4, b1, b3, b4, c1, c3, c4);

    adj->fMap[0][2] = Determinant3(b1, b2, b4, c1, c2, c4, d1, d2, d4);
    adj->fMap[1][2] = -Determinant3(a1, a2, a4, c1, c2, c4, d1, d2, d4);
    adj->fMap[2][2] = Determinant3(a1, a2, a4, b1, b2, b4, d1, d2, d4);
    adj->fMap[3][2] = -Determinant3(a1, a2, a4, b1, b2, b4, c1, c2, c4);

    adj->fMap[0][3] = -Determinant3(b1, b2, b3, c1, c2, c3, d1, d2, d3);
    adj->fMap[1][3] = Determinant3(a1, a2, a3, c1, c2, c3, d1, d2, d3);
    adj->fMap[2][3] = -Determinant3(a1, a2, a3, b1, b2, b3, d1, d2, d3);
    adj->fMap[3][3] = Determinant3(a1, a2, a3, b1, b2, b3, c1, c2, c3);

    adj->NotIdentity();
    return adj;
}