views:

76

answers:

2

I have a map of the US, and I've got a lot of pixel coordinates on that map which correspond to places of interest. These are dynamically drawn on the map at runtime according to various settings and statistics.

I now need to switch over to a different map of the US which is differently sized, and the top left corner of the map is in a slightly place in the ocean.

So I've manually collected a small set of coordinates for each map that correspond to one another. For example, the point (244,312) on the first map corresponds to the point (598,624) on the second map, and (1323,374) on the first map corresponds to (2793,545) on the second map, etc.

So I'm trying to decide the translation for the X and Y dimensions. So given a set of points for the old and new maps, how do I find the x' = A*x + C and y' = B*x + D equations to automatically translate any point from the old map to the new one?

+3  A: 

You have the coordinates of two points on both maps, (x1,y1), (x'1, y'1), (x2, y2) and (x'2, y'2).

A = (x'1 - x'2)/(x1 - x2)
B = (y'1 - y'2)/(y1 - y2)
C = x'1 - A x1
D = y'1 - B y1

P.S. Your equations imply a simple scaling/translation from one map to another. If you're worried about using different projections from globe to plane, the equations will be more complicated.

Beta
+3  A: 

To get result more robust against inaccuracies more that two points may help. In this case if you assume only shift and scaling Least squares fit may help: Wikipedia

Basically you minimize sum( (A*xi+B-xi')^2 + (C*yi+D-yi')^2 ) by selecting optimal A,B,C,D.

maxim1000