I am trying to fit a transformation from one set of coordiantes to another. x' = R + Px + Qy y' = S - Qx + Py Where P,Q,R,S are constants, P = scale*cos(rotation). Q=scale*sin(rotation) There is a well known 'by hand' formula for fitting P,Q,R,S to a set of corresponding points. But I need to have an error estimate on the fit - so I need a least squares solution. I'm having trouble working out how to do this for first principles for data sets with x and y in them. Can anyone point to an example/tutorial/code sample of how to do this ?