# [R] solving for a 2D transformation matrix

From: Russell Senior <seniorr_at_aracnet.com>
Date: Sat 03 Jul 2004 - 14:59:14 EST

We have recently digitized a set of points from some scanned engineering drawings (in the form of PDFs). The digitization resulted in x,y page coordinates for each point. The scans were not aligned perfectly so there is a small rotation, and furthermore each projection (e.g. the yz-plane) on the drawing has a different offset from the page origin to the projection origin. From the dimensions indicated on the drawing, I know the intended "world" coordinates of a subset of the points. I want to use this subset of points to compute a best-fit transformation matrix so that the remaining points can be converted to world coordinates.

The transformation matrix is (I think) of the form:

[ x' ] [ a11 a12 a13 ] [ x ]

| y' | = | a21 a22 a23 | | y |
[ w' ] [ a31 a32 a33 ] [ w ]

where:

x,y = page coordinates
x',y' = world coordinates

a13 = translation of x
a23 = translation of y

```    a11 = scale * cos(theta)
a12 = sin(theta)
a21 = -sin(theta)
a22 = scale * cos(theta)

a31 = 0
```

a31 = 0
a33 = 1
w' = 1
w = 1

Can anyone give me a pointer on how to go about solving for the transformation matrix given a set of points, where x,y and x',y' are available? I sense the presence a solution lingering in the murky mists, (some kind of least squares?) but I am not sure what it is or how to go about it exactly.

```--