Skip to content

Instantly share code, notes, and snippets.

@jaybo
Last active August 11, 2016 03:53
Show Gist options
  • Save jaybo/49323e450d3a8932656c4176e5eb0884 to your computer and use it in GitHub Desktop.
Save jaybo/49323e450d3a8932656c4176e5eb0884 to your computer and use it in GitHub Desktop.
2D boundary interpolation in numpy
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
x = [0, 1, 1, 0, 0]
y = [0, 0, 1, 1, 0]
orig_len = len(x)
t = np.arange(len(x))
ti = np.linspace(0, orig_len-1, 100 * orig_len)
xi = interp1d(t, x, kind='linear')(ti)
yi = interp1d(t, y, kind='linear')(ti)
print xi
print yi
fig, ax = plt.subplots()
ax.plot(xi, yi)
ax.plot(x, y)
ax.margins(0.05)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment