27 lines
No EOL
705 B
Python
27 lines
No EOL
705 B
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
def interp2_normalized(f00, f10, f01, f11, x, y):
|
|
a00 = f00
|
|
a10 = f10 - f00
|
|
a01 = f01 - f00
|
|
a11 = f11 - f10 - f01 + f00
|
|
return a00 + a10*x + a01*y + a11*x*y
|
|
|
|
def interp2(x0, y0, x1, y1, f00, f10, f01, f11, x, y):
|
|
x_n = (x - x0)/(x1 - x0)
|
|
y_n = (y - y0)/(y1 - y0)
|
|
return interp2_normalized(f00, f10, f01, f11, x_n, y_n)
|
|
|
|
if __name__ == '__main__':
|
|
f00, f10, f01, f11 = 0, 1, 2, -3
|
|
N = 101
|
|
F = np.zeros((N,N))
|
|
for i in range(N):
|
|
for j in range(N):
|
|
F[i,j] = interp2_normalized(f00, f10, f01, f11, i/(N-1), j/(N-1))
|
|
|
|
plt.figure()
|
|
plt.imshow(F)
|
|
plt.colorbar()
|
|
plt.show() |