R – Linear relationships for two (x,y) graphs


I have x,y data coming in from a [coordinates1] database (GIS – but this could be any database). I have my application with it's own coordinate system, referencing THE SAME MAP.

I have established that a linear relationship exists between coordinates1 (x,y) and coordinates2(x,y) as I have subtracted two different coordinates1 and coordinates2 (dividing x1 with x2 and y1 with y2) and in all cases I get them both showing 0.724 or 0.141 or 0.825 respectively i.e. coordinates1 + coordinates2.

What I now need to figure out – or you help – is that if coordinates1(100000,200000) and coordinates2(0.125,0.255) how do I calculate coordinates2(x,y) from the data in coordinates1(x,y)?

Best Solution

For the sake of clarity, I'm going to call coordinates in your base (xn, yn), and coordinates in your target (un, vn).

Now, if we assume:

  1. The origins of the two coordinate systems are the same.
  2. The orientation of the two coordinate systems are the same (i.e. one is not rotated with respect to the other).

In this case you only need one set of points {(x1, y1), (u1, v1)} to determine the location of (un, vn):

  • un = u1/x1 * xn
  • vn = v1/y1 * yn

Note: we must have x1 ≠ 0, y1 ≠ 0

On the other hand, if the two coordinate systems have different origins (but they are still not rotated with respect to one another), we will need two sets of points {(x1, y1), (u1, v1)} and {(x2, y2), (u2, v2)}:

  • un = (u2 - u1)/(x2 - x1) * (xn - x1) + u1
  • vn = (v2 - v1)/(y2 - y1) * (yn - y1) + v1

Note: we must have x1x2, y1y2

Now, if the two coordinate systems are rotated with respect to one another, you need (I believe) one more set of matching coordinates. But it doesn't sound like you need that (unless one of your maps has north pointing in a direction other than straight up), so I'm not going to work out the math now. :)