Advertisement
gmlscripts

ds_grid_get_bilinear

Aug 1st, 2014
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// ds_grid_get_bilinear(id,x,y)
  2. //
  3. //  Returns the bilinear interpolation of the four grid
  4. //  cells surrounding a given fractional coordinate.
  5. //
  6. //      id          grid data structure, real
  7. //      x,y         coordinate pair, real
  8. //
  9. /// GMLscripts.com/license
  10. {
  11.     var ix,iy,fx,fy,A,B;
  12.     ix = floor(argument1);
  13.     iy = floor(argument2);
  14.     fx = argument1 - ix;
  15.     fy = argument2 - iy;
  16.  
  17.     A = ds_grid_get(argument0,ix,iy);
  18.     B = ds_grid_get(argument0,ix+1,iy);
  19.     A += fy*(ds_grid_get(argument0,ix,iy+1)-A);
  20.     B += fy*(ds_grid_get(argument0,ix+1,iy+1)-B);
  21.     return A+fx*(B-A);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement