Sunday, 15 February 2015

c# - How could i speed up this method -



c# - How could i speed up this method -

i`m attempting implement iwave water surface simulation outlined in simulating ocean water (pdf) there code extract @ end.

the particular method calculating vertical derivative using convolution kernel

for(int ix = 6; ix < iwidth - 6; ix++) { for(int iy = 6; iy < iheight - 6; iy++) { int index = ix + iwidth * iy; float vd = 0; // apply convolution for(int iix = -6; iix <= 6; iix++) { for(int iiy = -6; iiy <= 6; iiy++) { int iindex = ix + iix + iwidth * (iy + iiy); vd += kernel[iix + 6, iiy + 6] * height[iindex]; } } vertical_derivative[index] = vd; } }

at every point in height (a flattened 2x2 array) convolution kernel (2x2 array size 13) used calculate vertical derivative. becomes slow real time interaction when height grid sized (128x128) larger grid. how speed up?

a faster way carry out convolution create utilize of identity ft(conv(f, g)) = ft(f) ft(g), is, fourier transform of convolution of 2 functions pointwise product of fourier transforms. conv(f, g) = ft^-1 (ft(f) ft(g)) ft^-1 inverse fourier transform. utilize fast fourier transform.

c# math optimization for-loop simulation

No comments:

Post a Comment