I am interpolating data from the vertices of a quadrilateral to any random point inside the quadrilateral. I implement this by first doing a coordinate transformation which reshapes the quadrilateral to a unit square and then using bilinear interpolation. Does any of the python libraries already have an implementation to do this?
Asked
Active
Viewed 314 times
0
-
If you are already "interpolating data", then you must have a solution. What more do you want ? – May 03 '22 at 09:04
1 Answers
0
Bilinear interpolation between the corners of a quadrilateral gives the coordinates
P = (P00 (1-u) + P10 u) (1-v) + (P01 (1-u) + P11 u) v
= P00 + (P10-P00) u + (P01-P00) v + (P11-P10-P01+P00) uv.
This forms a system of two quadratic equations in the unknowns u
, v
. If P
is inside the quadrilateral, u, v ε [0, 1]
.
If we take the dot and cross products with P11-P10-P01+P0
, the system takes the form
A + B u + C v + D uv = 0
a + b u + c v = 0
from which we eliminate v
by
c (A + B u) - (C + D u) (a + b u) = -b D u² + (B c - b C - a D) u + (A c - a C) = 0
which is quadratic univariate. Compute the roots and keep the one in the domain. From u
you get v
.