Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am a bit confused how the formula is different from a simple lerp.

    k(x) = 1/x
    
        y_i * k(x - x_i) + y_i+1 * k(x_i+1 - x)
    F = --------------------------------------- =
             k(x - x_i) + k(x_i+1 - x)
    
      y_i / (x - x_i) + y_i+1 / (x_i+1 - x)
    = --------------------------------------- =
           1 / (x - x_i) + 1 / (x_i+1 - x)
    
      y_i * (x_i+1 - x) / A + y_i+1 * (x - x_i) / A
    = ---------------------------------------------
           (x_i+1 - x) / A + (x - x_i) / A
    
    where A = (x - x_i) * (x_i+1 - x)
    scaling to x_i+1 - x_i = 1, and using a = (x - x_i)
    
    F = (1 - a) * y_i + a * y_i+1
The only time this wouldn't hold is when A = 0, but then F is not defined anyway. However, the graph of F shown is decidedly not that of the lerp function.


Oh, it seems that a square fell off. It should have been 1/x^2. 1/x works fine for bitmaps, but in 1-dimensional case 1/x indeed turns the whole thing into linear interpolation, you're right.


Yep, there is a square in the source:

    // interpolation/extrapolation with no basis functions
    var weight2d1 = 2;
    const wf2d1 = function(x) {return 1./Math.pow(x, weight2d1);}




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: