Algorithms, Blockchain and Cloud

C/C++ Function to Compute the Bilinear Interpolation

Bilinear_interpolation

Bilinear Interpolation (BI) is a very useful mathematical approach that you can use to estimate any given value in a two dimensional grid.

Bilinear_interpolation

If you don’t like Matlab (me neither), then the following C/C++ function may be useful to you. You can also easily use this code in other C-like programming languages e.g. Java with little modification. You can also use double type if the precision is of importance.

For more information on Bilinear Interpolation, you can visit the Wiki in details.

// https://helloacm.com
inline float 
BilinearInterpolation(float q11, float q12, float q21, float q22, float x1, float x2, float y1, float y2, float x, float y) 
{
	float x2x1, y2y1, x2x, y2y, yy1, xx1;
	x2x1 = x2 - x1;
	y2y1 = y2 - y1;
	x2x = x2 - x;
	y2y = y2 - y;
	yy1 = y - y1;
	xx1 = x - x1;
	return 1.0 / (x2x1 * y2y1) * (
		q11 * x2x * y2y +
		q21 * xx1 * y2y +
		q12 * x2x * yy1 +
		q22 * xx1 * yy1
	);
}

–EOF (The Ultimate Computing & Technology Blog) —

258 words
Last Post: C/C++ Coding Exercise - Find Minimum in Rotated Sorted Array - Leetcode Online Judge
Next Post: How To Block Google Domains in Adsense?

The Permanent URL is: C/C++ Function to Compute the Bilinear Interpolation (AMP Version)

Exit mobile version