fill_gap.py 827 B

123456789101112131415161718192021222324252627282930313233
  1. """Interpolate gap between two functions"""
  2. # https://www.youtube.com/watch?v=vD5g8aVscUI
  3. import numpy as np
  4. from vedo.pyplot import plot
  5. from vedo import settings
  6. settings.remember_last_figure_format = True # useful for pf += plot(...)
  7. x1 = np.linspace(-2,2, num=100)
  8. x = np.linspace(-2,2, num=100)
  9. x2 = np.linspace(-2,2, num=100)
  10. fx = np.sin(x1*3) - 1
  11. gx = x2*x2/3 -1
  12. def phi(x):
  13. psi = np.exp(-1/x)
  14. psi_1 = np.exp(-1/(1-x))
  15. phi = psi / (psi + psi_1)
  16. phi = np.where(x<=0, 0, phi)
  17. phi = np.where(x>1, 1, phi)
  18. return phi
  19. w = phi(x)
  20. h = (1-w) * fx + w * gx
  21. pf = plot(x1[:50], fx[:50], xlim=[-2,2], ylim=[-2,1.5], lw=5, title=__doc__)
  22. pf += plot(x[50:75], h[50:75], c='red5')
  23. pf += plot(x2[75:], gx[75:], lw=5)
  24. pf += plot(x[50:75], w[50:75], c='green4', lw=1)
  25. pf.show(mode='image', zoom='tight')