Deriving 2D transforms from 4 points

Source

Given 4 pairs of points of the form , compute the homography matrix

We write the pre-transformed points as and the transformed points as

Defining the equation

After cross-multiplying and re-arranging:

We solve for (i. e. ).

This gets us the 3x3 . However, matrix3d takes a 4x4 matrix. Since we don’t care about , we can make it just map back to itself: