liveBook · Manning

Two-point transformation

As explained in Geometry for Programmers

A two-point transformation is a linear transformation specified by the destinations of a pair of input points.

A two-point transformation is a 2D linear transformation determined by specifying where two input points should go. Its matrix has four unknown entries, matching the four coordinate equations supplied by two points. section 4.2.1

The number of point constraints matters:

  • One point gives two equations for four matrix entries, leaving a continuum of solutions. section 4.2.1
  • Two points give exactly four equations, allowing the matrix to be solved symbolically. section 4.2.1
  • Three points normally overspecify the four-entry matrix and may produce no solution. section 4.2.1

Solve the transformation symbolically

Represent the source coordinates as (x1, y1) and (x2, y2), and their destinations as (xt1, yt1) and (xt2, yt2). Solving the four resulting equations for a11, a12, a21, and a22 produces the transformation matrix. section 4.2.1

Listing 4.1 Computing the matrix for the linear transformation symbolically
from sympy import *
 
a11, a12, a21, a22 = symbols('a11 a12 a21 a22')    #1
x1, y1, x2, y2 = symbols('x1 y1 x2 y2')            #2
xt1, yt1, xt2, yt2 = symbols('xt1 yt1 xt2 yt2')    #3
 
solution = solve([
    a11 * x1 + a12 * y1 - xt1,                     #4
    a21 * x1 + a22 * y1 - yt1,
    a11 * x2 + a12 * y2 - xt2,
    a21 * x2 + a22 * y2 - yt2
], (a11, a12, a21, a22))
 
print(solution)

Inspect the executable SymPy listing that constructs and solves the four-equation system. section 4.2.1

How Geometry for Programmers covers it

How deep it goes
Derives the four-equation symbolic system and contrasts under- and overspecification, while deferring broader transformation construction.
Examples
Uses two source points, two destination points, a SymPy listing, and the resulting symbolic matrix entries.
What you can do after
Build it from scratch by forming and solving the four symbolic coordinate equations with SymPy.
How it connects
Connects linear transformations with Euclidean space, matrices, linear equations, and row-vector or column-vector conventions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.