Assume that the plane looks like this:
Construct a "local basis" of the plane, with the:
- X-axis parallel to AD / BC
- Y-axis parallel to AB / CD
- Z-axis parallel to the normal
- Origin O at the center of the quad
The transformation matrix can be decomposed into 3 components:
1 – Scale
Since the original quad has dimensions of 1x1 units, the scaling factor along the X and Y local axes are simply the side lengths, i.e. the lengths of AD and AB respectively. Ignore the Z scaling factor since the quad is planar.
Therefore the scaling component is given by:
2 - Rotation
The rotational component can be directly constructed from the local basis axes X, Y, Z; each vector (normalized) is the corresponding column of the matrix.
Therefore the rotational component is given by:
3 - Translation
This is the easiest one; the translation vector is simply the absolute coordinate of the quad's center O, and is equal to the last column of the matrix.
Therefore the translational component is given by:
The final matrix can be obtained by multiplying the above in the following order:
i.e. the components are applied in the order 1 ⇨ 2 ⇨ 3.