Questions tagged [linear-interpolation]

Linear interpolation is the process of approximating intermediate values given an assumption that the ranges of missing data look roughly like straight lines.

Linear interpolation is largely used for its simplicity and is typically more effective given a greater density of data. The more complex the underlying relationship of the quantities involved, the less likely linear interpolation is to provide a good value estimates.

In scientific software for statistical computing and graphics, function approx performs 1D linear interpolation.

437 questions
54
votes
7 answers

Floating point linear interpolation

To do a linear interpolation between two variables a and b given a fraction f, I'm currently using this code: float lerp(float a, float b, float f) { return (a * (1.0 - f)) + (b * f); } I think there's probably a more efficient way of doing…
Thomas O
  • 6,026
  • 12
  • 42
  • 60
44
votes
7 answers

How to implement linear interpolation?

Say I am given data as follows: x = [1, 2.5, 3.4, 5.8, 6] y = [2, 4, 5.8, 4.3, 4] I want to design a function that will interpolate linearly between 1 and 2.5, 2.5 to 3.4, and so on using Python. I have tried looking through this Python tutorial,…
Helpless
  • 467
  • 1
  • 4
  • 4
42
votes
2 answers

How exactly does OpenGL do perspectively correct linear interpolation?

If linear interpolation happens during the rasterization stage in the OpenGL pipeline, and the vertices have already been transformed to screen-space, where does the depth information used for perspectively correct interpolation come from? Can…
AIGuy110
  • 1,025
  • 1
  • 10
  • 11
32
votes
6 answers

Calculate RGB value for a range of values to create heat map

I am trying to create a heat map with python. For this I have to assign an RGB value to every value in the range of possible values. I thought of changing the color from blue (minimal value) over green to red (maximal value). The picture example…
aldorado
  • 4,394
  • 10
  • 35
  • 46
30
votes
4 answers

Python regularise irregular time series with linear interpolation

I have a time series in pandas that looks like this: Values 1992-08-27 07:46:48 28.0 1992-08-27 08:00:48 28.2 1992-08-27 08:33:48 28.4 1992-08-27 08:43:48 28.8 1992-08-27 08:48:48 29.0 1992-08-27…
Diane
  • 303
  • 1
  • 3
  • 4
18
votes
2 answers

Interpolating timeseries

I have two sets of data with different time stamps. One set of data contains calibration data, the other contains sample data. The calibration is much less frequent than the samples. What I would like to do is interpolate the calibration data (low…
Alex Archibald
  • 407
  • 1
  • 6
  • 14
17
votes
3 answers

Best way to interpolate values in SQL

I have a table with rate at certain date : Rates Id | Date | Rate ----+---------------+------- 1 | 01/01/2011 | 4.5 2 | 01/04/2011 | 3.2 3 | 04/06/2011 | 2.4 4 | 30/06/2011 | 5 I want to get the output…
Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
16
votes
1 answer

What's the common name for the inverse of the lerp function?

The function lerp() is a common function in programming languages: lerp(a, b, t) = a + t * (b - a). Now for very many situatons I have an inverse function: fraction(x, a, b) = (x - a) / (b - a). This function is built so that lerp(a, b,…
15
votes
2 answers

fastest way to use numpy.interp on a 2-D array

I have the following problem. I am trying to find the fastest way to use the interpolation method of numpy on a 2-D array of x-coordinates. import numpy as np xp = [0.0, 0.25, 0.5, 0.75, 1.0] np.random.seed(100) x = np.random.rand(10) fp =…
Eric B
  • 1,635
  • 4
  • 13
  • 27
14
votes
4 answers

linear interpolate missing values in time series

I would like to add all missing dates between min and max date in a data.frame and linear interpolate all missing values, like df <- data.frame(date = as.Date(c("2015-10-05","2015-10-08","2015-10-09", …
ckluss
  • 1,477
  • 4
  • 21
  • 33
14
votes
1 answer

Android: How to make horizontal progress bar using Interpolator?

I have a progress bar view like this: It lasts 3 second, so how to use interpolator to make…
Lucky Luke
  • 609
  • 1
  • 6
  • 18
14
votes
3 answers

Cubic/Curve Smooth Interpolation in C#

Below is a cubic interpolation function: public float Smooth(float start, float end, float amount) { // Clamp to 0-1; amount = (amount > 1f) ? 1f : amount; amount = (amount < 0f) ? 0f : amount; // Cubicly adjust the amount value. …
Rob
  • 1,687
  • 3
  • 22
  • 34
13
votes
2 answers

How to find points by linear interpolation

I have two points (5,0.45) & (6,0.50) and need to find the value when x=5.019802 by linear interpolation But how to code it in R? I tried the code below but just got a graph. x <- c(5,6) y <- c(0.45,0.50) interp <-…
Ys Kee
  • 145
  • 1
  • 5
13
votes
1 answer

Bilinear image interpolation / scaling - A calculation example

I would like to ask you about some bilinear interpolation / scaling details. Let's assume that we have this matrix: |100 | 50 | |70 | 20 | This is a 2 x 2 grayscale image. Now, I would like scale it by factor of two and my matrix looks like…
12
votes
1 answer

obj-c linear interpolation between two numbers

Just wondering if there are methods already implemented for handling linear interpolation between two numbers in foundation/something else that comes with Xcode? It's hardly an advanced thing to implement yourself, but I usually find myself…
quano
  • 18,812
  • 25
  • 97
  • 108
1
2 3
29 30