0

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 ?

TheEagle
  • 149
  • 1
    If your rectangles and your point share the same coordinate system why does it matter that the rectangles were rotated ? You can't just take the coordinates of $A,B,C,D$ and the four elevations and interpolate to get the elevation at $P$ ? – Kurt G. Aug 28 '22 at 16:15
  • @KurtG. I have added an explanation ! :) – TheEagle Aug 28 '22 at 16:50
  • The rotation swaps longitude with latitude. The tables should therefore follow that new logic. – Kurt G. Aug 28 '22 at 17:24
  • @KurtG. okay, but what do I do when the grid is rotated say 293.1 degrees ? Any trigonometry possible here, maybe ? – TheEagle Aug 28 '22 at 17:32
  • This problem has nothing to do with rotations. Instead of labelling the points $A,B,C,D$ think in terms of their coordinates $(x_i,y_i)$ and apply the formulas in the my answer. Clearly, if $x_1=x_2$ or $y_1=y_2$ we don't have a rectangle and it is impossible to interpolate in two dimensions. – Kurt G. Aug 28 '22 at 17:55

1 Answers1

2

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}

Kurt G.
  • 14,198
  • looks promising, thanks ! But I am a bit confused, about what $f(x, y)$ is defined as in each of the functions - (3) is probably using (1) and (2), but what is used in (1) and (2) ? – TheEagle Aug 28 '22 at 17:55
  • Additionally, should $f(x2,y1)(x−x1)$ be read as $f(x2,y1) · (x−x1)$ ? – TheEagle Aug 28 '22 at 17:56
  • In (1) and (2) you use known elevations at the four points and in (3) you use pre-interpolated values in the $x$-direction to interpolate in the $y$-direction. Yes. The dot in multiplications is omitted. – Kurt G. Aug 28 '22 at 17:56
  • Thank you very much ! :) – TheEagle Aug 28 '22 at 17:57