How to interpolate from rotated rectangle / grid?

122 Views Asked by At

I have a grid made from rectangles, rotated by an arbitrary angle. Each point of the grid is defined by a GPS coordinate vector of the form $(lon, lat)$ and has an elevation assigned. Now, I have an arbitrary point $P$ defined by a vector $(lon, lat)$ that lies within that grid, and I know which of the cells (rectangles) $P$ lies on. That rectangle is defined by the four corner points $ABCD$, in clockwise order.

I need to get the elevation at the point $P$ by interpolating between the elevations of $ABCD$. Now, if the grid were not rotated, that would be fairly easy to do, by using an interpolation table. Example: $A = (1.1, 1) elev = 1000$, $B = (1.2, 1) elev = 1100$, $C = (1.2, 0.9) elev = 1200$, $D = (1.1, 0.9) elev = 1100)$, $P = (1.025, 0.95)$

| Lon | Elevation |
| --- | --------- |
| 1.1 | 1000      |
| 1.2 | 1100      |

for points $A$ and $B$ giving elevation $a = 1025$,

| Lon | Elevation |
| --- | --------- |
| 1.1 | 1100      |
| 1.2 | 1200      |

for points $C$ and $D$, giving elevation $b = 1125$, and

| Lat | Elevation |
| --- | --------- |
| 0.9 | 1125      |
| 1   | 1025      |

to interpolate between the two previous tables, giving 1075. Now if I did the same thing on a rotated grid, it would obviously not work - consider a grid rotated 90°, where we have: $A = (1.2, 1) elev = 1000$, $B = (1.2, 0.9) elev = 1100$, $C = (1.1, 0.9) elev = 1200$, $D = (1.1, 1) elev = 1100)$, $P = (1.025, 0.95)$

| Lon | Elevation |
| --- | --------- |
| 1.2 | 1000      |
| 1.2 | 1100      |

for points $A$ and $B$,

| Lon | Elevation |
| --- | --------- |
| 1.1 | 1100      |
| 1.1 | 1200      |

for points $C$ and $D$, and

| Lat | Elevation |
| --- | --------- |
| 1   | 1125      |
| 1   | 1025      |

to interpolate between the two previous tables. You can see that this will give wrong results, since there is nothing to interpolate from.

So, instead of interpolation tables based on longitude / latitude, I need to do the whole thing with distances somehow. How would I do that ?

1

There are 1 best solutions below

4
On BEST ANSWER

Your elevation is a function $f(x,y)$ of longitude $x$ and latitude $y$ and your points of the rectangle are $A=(x_1,y_1),B=(x_1,y_2),C=(x_2,y_1),D=(x_2,y_2)$. The formulas you should be using to interpolate are \begin{align} \tag{1}f(x,y_1)&=\frac{f(x_1,y_1)(x_2-x)+f(x_2,y_1)(x-x_1)}{x_2-x_1}\\ \tag{2}f(x,y_2)&=\frac{f(x_1,y_2)(x_2-x)+f(x_2,y_2)(x-x_1)}{x_2-x_1}\\ \tag{3}f(x,y)&=\frac{f(x,y_1)(y_2-y)+f(x,y_2)(y-y_1)}{y_2-y_1}\,. \end{align}