# Align two sequence of points using linear regression

I have two sets of points in 2D space, S1={a1,a2,....,an} and S2={b1,b2,....,bn}. I would like to align S2 such that min(sum(|S2i – S1i.T|^2)) from i=1 to n. where T is a 2×2 matrix for aligning the points of S1i, and S2i are the points for the target sequence.

I would like to achieve that using linear regression. Any idea how can estimate the matrix T. Matlab code could be very helpful also.

• Apart from that, do you want matrix T to be a rotation matrix, or not necessarily? – amoeba Feb 15 '16 at 14:28
• @amoeba since the sequences S1 and S2 take varies directions, the rotation is required to align S2 into S1 with minimum error. – Omar14 Feb 15 '16 at 14:43
• Still not clear: do you want to constrain T to be a rotation matrix (that's a special kind of 2x2 matrix) or do you want to find the best T whatever it will be? – amoeba Feb 15 '16 at 14:45
• @amoeba I need T whatever it (as 2x2 matrix). – Omar14 Feb 15 '16 at 14:47