[Bug 12969] bilinear interpolation

http://www.w3.org/Bugs/Public/show_bug.cgi?id=12969

--- Comment #1 from j.chetwynd <j.chetwynd@btinternet.com> 2011-06-16 12:58:35 UTC ---
    /**
    * linear interpolation
    * t value between 0 and 1, a = initial value, b = final value
    */

    function lerp(t, a, b) {
      return (+a+(b-a)*t);
    }

    /**
    * bilinear interpolation of intermediate values in two dimensions
    * tx = number of intermediate x values required + 1
    * ty= number of intermediate y values required + 1
    * x = width
    * y = height
    * arr = array of length x*y
    * out = array of length x*(tx-1)*y*(ty-1)
    */

    function blerp(tx, ty, arr, x, y){
      var out = [],
          outv = 0,
          k = 1,
          j = 0,
          i = 1;

      for(k; k<=ty; k++){
        for(j; j<x-1; j++){
          f = lerp(k/ty, arr[j], arr[x+j]);
          g = lerp(k/ty, arr[j+1], arr[x+j+1]);
          for(i; i<tx; i++){
            outv = lerp(i/tx, f, g);
            out.push(outv);
          }
          i = 1;
        }
        j=0;
      }
      return out;
    }

    var ex1 = blerp(10, 10, [0,10,100,110], 2, 2),
        ex2 = blerp(10, 10, [0,10,20,100,110,120], 3, 2);

    console.log(ex1.join(','));
    console.log("\n");
    console.log(ex2.join(','));

-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Thursday, 16 June 2011 12:58:36 UTC