BL2.ru

Bilinear interpolation (double linear interpolation)

Bilinear (double) interpolation for values that depend on two parameters, like a row × column table. Enter the four corner values and the point (x; y) to get the value, the surface equation and a map.

Calculate
Bilinear interpolation, like ordinary linear interpolation and extrapolation, allows you to find values of an unknown function, but the result of this function depends not on one variable but on two. You can also use the services Newton polynomial and Lagrange polynomial.

What it is

Bilinear (double linear) interpolation finds the value of a function of two variables f(x, y) when it is known only at four points — the corners of a rectangle. It is a direct generalisation of ordinary linear interpolation: there the value is sought between two points on a line, here inside a rectangle on a plane.

A typical case is a two-way table: one quantity along the rows (for example, temperature), another along the columns (pressure), and the value you need falls between rows and columns.

How it is calculated

The corner values f(x0, y0), f(x0, y2), f(x2, y0) and f(x2, y2) are known. We need f(x1, y1) for a point inside. The calculation is three ordinary linear interpolations:

  • along x on the lower side: f(x1, y0) — between f(x0, y0) and f(x2, y0);
  • along x on the upper side: f(x1, y2) — between f(x0, y2) and f(x2, y2);
  • along y between the two values found — this is f(x1, y1).

The calculator also finds the values on the left and right sides, f(x0, y1) and f(x2, y1), which is handy when you need a whole slice of the table. The general formula:

f(x1, y1) = f00·(1−t)(1−u) + f20·t(1−u) + f02·(1−t)u + f22·t·u,
where t = (x1 − x0) / (x2 − x0) and u = (y1 − y0) / (y2 − y0) are the fractions of the way along each axis (0 to 1 inside the rectangle).

The result does not depend on which axis you start with: going along y first and then along x gives the same number.

Example

Air temperature is known at altitudes 0 and 2 km above latitudes 40° and 60°. We need the temperature at 0.5 km above latitude 55°:

latitude 40° (y0)latitude 60° (y2)
altitude 0 km (x0)18 °C8 °C
altitude 2 km (x2)6 °C−4 °C
  • Fractions: t = (0.5 − 0) / (2 − 0) = 0.25, u = (55 − 40) / (60 − 40) = 0.75.
  • At latitude 40°: 18 + 0.25 · (6 − 18) = 15 °C.
  • At latitude 60°: 8 + 0.25 · (−4 − 8) = 5 °C.
  • Between them by latitude: 15 + 0.75 · (5 − 15) = 7.5 °C.

These are exactly the numbers the demo above shows.

Good to know

  • You need the four corners of a rectangle with sides parallel to the axes: x0 ≠ x2 and y0 ≠ y2. Scattered points need other methods (triangulation, inverse distance weighting).
  • It is not a plane. Along each axis the function changes linearly, but overall the surface is curved (a hyperbolic paraboloid), which is why it passes exactly through all four corners.
  • Accuracy is good when the function changes smoothly inside the cell. For a coarse table and a strongly non-linear dependence, use the nearest cell or bicubic interpolation.
  • Extrapolation. If the point is outside the rectangle (t or u outside 0…1), the calculator still computes it, but the error grows quickly with distance.

Where it is used

  • Two-way reference tables — engineering standards, heat transfer, hydraulics, water and steam properties: density or viscosity by temperature and pressure, a heat-transfer coefficient by flow speed and temperature.
  • Weather, maps, GIS — temperature, pressure or terrain height are known at regular grid nodes (weather models, digital elevation models), and you need a point between them.
  • Images and video — when a picture is enlarged or rotated, each new pixel is computed from its four neighbours; this is the "bilinear" mode in Photoshop, browsers and GPUs.
  • 3D graphics and games — texture filtering, terrain height under a character from a height map.
  • Engineering — pump, fan and engine performance maps (efficiency or power by speed and load), aerodynamic tables, sensor calibration tables with two parameters.
  • Finance — a rate or coefficient from a "term × amount" grid, option volatility surfaces (strike × maturity).
  • Studying — check a homework solution and see the intermediate values on every side of the rectangle.

How to use

  • Fill in the first and third rows: x0, y0, f(x0, y0) and x2, y2, f(x2, y2). In the second row put the point x1, y1 where you need the value.
  • The grey x and y fields below fill in by themselves — you only need to enter f(x0, y2) and f(x2, y0).
  • Press "Calculate". With the box inside the button ticked, it recalculates on every change.
  • Fractions (1/2), decimal commas (0,5) and expressions like sqrt(2) work.

FAQ

When is bilinear interpolation needed?
When a table value depends on two quantities at once and your point lies between both rows and columns.
How to enter table data?
x₀, x₂ are neighbouring row values, y₀, y₂ neighbouring column values, the four f values are at their intersections; x₁, y₁ is your point.
How to do it by hand?
Two linear interpolations along x (at y₀ and y₂), then one along y between the results.
What if there is only one parameter?