Proceed to Safety

Two-Dimensional Interpolation    

Robert P. Munafo, 2023 Feb 19

Two-dimensional interpolation, commonly called bilinear interpolation, is a technique for deriving values of points within a rectangle (or, within reason, any quadrilateral) given the values for the four corners.

In general, bilinear interpolation works in a Euclidean space with any number of dmensions; in such cases it remains a six-argument function of four vectors and two scalars. It has the argumentwise-linearity property of a bilinear map only when all four of the vectors (and one of the scalars) is kept constant. In the following we will stick with a two-dimensional vectors for the coordinates; however it is useful to note that the "rectangle" or "quadrilateral" could start on a plane (e.g. the parameter plane and then move anywhere in the 4-dimensional Julia-Mandelbrot space, and two-dimensional interpolation would still be valid.

Given a quadrilateral defined by four vertices with coordinates (a, b), (c, d), (e, f), and (g, h), and parameters p and q representing a location within the quadrilateral relative to its corners (with both parameters being in the range [0..1]) it is desired to compute the coordinates (v, w) of that location.

. . ' (9,9) . . ' ' . (1,7) ' * . . . . . . . . . . . . . (9,1) . . . ' ' (3,-2) '

example for p=0.6, q=0.2

An easy approach is to use ordinary linear interpolation along two opposite edges (the "top" and "bottom" edges of the quadrilateral) using the parameter p, yielding the coordinates of two points along those edges. As shown in the inverse interpolation article those coordinates will be:

( a(1-p)+c p , b(1-p)+d p )
( e(1-p)+g p , f(1-p)+h p )

then we can interpolate between these points using the parameter q. The result is:

v = (a(1-p)+c p)(1-q) + (e(1-p)+g p)q
w = (b(1-p)+d p)(1-q) + (f(1-p)+h p)q

This calculation can be reversed to find the values of p and q when all the coordinates a, b, c, d, e, f, g, h, v, w are known; see the article Inverse Interpolation for a Quadrilateral.


The following program sets up an example and prints the calculations as it goes; you can use the example values to verify that your implementation is working.

// Two-dimensional interpolation: given corners of a quadrilateral // and parameters p,q (representing a position within the quadrilateral) // find the coordinates (v,w) of that position. // // p=0.6 (9,9) // (5.8,8.2) // (1,7) // (5.96,6.52) q=0.2 // // // // // (9,1) // (6.6,-0.2) // (3,-2) a = 1 b = 7 c = 9 d = 9 e = 3 f = -2 g = 9 h = 1 p = 0.6 q = 0.2    // Interpolate along the top and bottom edges r = a*(1-p) + c*p s = b*(1-p) + d*p print r, s // should print 5.8 and 8.2 t = e*(1-p) + g*p u = f*(1-p) + h*p print t, u // should print 6.6 and -0.2    // Interpolate between (r,s) and (t,u) by q to get final answer v = r*(1-q) + t*q w = s*(1-q) + u*q print v, w // should print 5.96 and 6.52

revisions: 20230219 first version; 20230620 add intro paragraph

From the Mandelbrot Set Glossary and Encyclopedia, by Robert Munafo, (c) 1987-2024.

Mu-ency main pageindexrecent changesDEMZ

Robert Munafo's home pages on AWS    © 1996-2024 Robert P. Munafo.    about    contact
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Details here.

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 2023 Jun 21. s.27