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

  • Game Physics Cookbook
  • Gabor Szauer
  • 267字
  • 2021-04-02 20:27:28

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.

主站蜘蛛池模板: 德庆县| 嘉黎县| 石台县| 福海县| 惠州市| 格尔木市| 义乌市| 建德市| 买车| 青田县| 普宁市| 靖远县| 东台市| 青阳县| 华安县| 乐安县| 东乡县| 安义县| 柳林县| 新沂市| 林甸县| 北安市| 宜春市| 连江县| 宜兰县| 义马市| 东台市| 板桥市| 桃江县| 桐庐县| 丰都县| 江西省| 错那县| 北海市| 永康市| 县级市| 邳州市| 红桥区| 古田县| 沙坪坝区| 黄骅市|