官术网_书友最值得收藏!

Determinant of a 2x2 matrix

Determinants are useful for solving systems of linear equations; however, in the context of a 3D physics engine, we use them almost exclusively to find the inverse of a matrix. The determinant of a matrix M is a scalar value, it's denoted as Determinant of a 2x2 matrix.The determinant of a matrix is the same as the determinant of its transpose Determinant of a 2x2 matrix.

We can use a shortcut to find the determinant of a 2 X 2 matrix; subtract the product of the diagonals. This is actually the manually expanded form of Laplace Expansion; we will cover the proper formula in detail later:

Determinant of a 2x2 matrix

One interesting property of determinants is that the determinant of the inverse of a matrix is the same as the inverse determinant of that matrix:

Determinant of a 2x2 matrix

Finding the determinant of a 2 X 2 matrix is fairly straightforward, as we have already expanded the formula. We're just going to implement this in code.

How to do it…

Follow these steps to implement a function which returns the determinant of a 2 X 2 matrix:

  1. Add the declaration for the determinant function to matrices.h:
    float Determinant(const mat2& matrix);
  2. Add the implementation for the determinant function to matrices.cpp:
    float Determinant(const mat2& matrix) {
        return matrix._11 * matrix._22 –
               matrix._12 * matrix._21;
    }

How it works…

Every square matrix has a determinant. We can use the determinant to figure out whether a matrix has an inverse or not. If the determinant of a matrix is non-zero, then the matrix has an inverse. If the determinant of a matrix is zero, then the matrix has no inverse.

主站蜘蛛池模板: 塔河县| 霍山县| 赣州市| 盱眙县| 名山县| 任丘市| 宿州市| 广宁县| 乃东县| 屯留县| 都昌县| 广南县| 平罗县| 浙江省| 沂南县| 岳阳市| 社旗县| 遂川县| 承德市| 和平区| 酒泉市| 万山特区| 瓮安县| 高陵县| 澄迈县| 横峰县| 正宁县| 安岳县| 梅州市| 沂南县| 台安县| 苗栗县| 渑池县| 鸡东县| 永德县| 顺平县| 南雄市| 苏尼特左旗| 正蓝旗| 台江县| 黑龙江省|