Iterative Bilinear Interpolation on Quadrilateral

21 Views Asked by At

I've been working on a personal project where I am looking to do a manual NTv2 geographic coordinate transformation. As of right now, I'm trying to get my math correct before expanding it across an entire grid. With the coordinates on the grid, they are very slightly off from being a perfect rectangle (coordinates on practically the same x or y are off by about 0.0001 degrees).

In this case I've decided to classify coordinate 1 as the bottom left reference coordinate, 2 as the bottom right, 3 as the top left, and 4 as top right.

First, with my target coordinate and 4 points that encapsulate the target, I do a bilinear interpolation doing the following:

  1. Find the weights of the four coordinates on the target for $(x_{1},y{_1}), (x_{2},y_{2}), (x_{3},y_{3}), $and$ (x_{4},y_{4}).$:
  • $dx = (x - x_{1})/(x_{2} - x_{1})$
  • $dy = (y - y_{1})/(y_{4} - y_{2})$
  • $w_{00} = (1 - dx)(1-dy)$
  • $w_{01} = dx(1-dy)$
  • $w_{10} = (1-dx)dy$
  • $w_{11} = dxdy$
  1. Apply weights to find a shift:
  • $x_{shift} = x_{shift 1}w_{00} + x_{shift3}w_{10} + x_{shift2}w_{01} + x_{shift4}w_{11}$
  • $y_{shift} = y_{shift1}w_{00} + y_{shift3}w_{10} + y_{shift2}w_{01} + y_{shift4}w_{11}$
  1. Add shifts to target coordinate to find the converted coordinate.
  • $x_{conv} = x + x_{shift}$
  • $y_{conv} = y + y_{shift}$

The problem I am finding is that the coordinate conversion is very slightly off from the expected result (about a 0.0001 degree difference). I tried to incorporate the following iterative process to try to refine the results, but it ends up diverging from the expected result.

  1. Take the converted coordinate and complete another bilinear interpolation using the same grid that it is still encapsulated in.

  2. Take the new coordinate just calculated and subtract it from the old coordinate to find the difference. $diff(x,y) = (x,y)_{new} - (x,y)_{conv}$

  3. Repeat the process, incorporating the new converted coordinate into step 1. The process is supposed to stop when the difference goes below the tolerance.

As said earlier, it does end up diverging. I was wondering if anyone had any input on my math as I am relatively fresh at doing this kind of math, especially to the accuracy required. Any help would be appreciated!