LoginSignup
1
1

波紋を作ってみた

Posted at

物理の授業で2点の水面に振動を加えると波紋ができると習いましたが実際どんな感じなのかPythonでやってみました

import matplotlib.pyplot as plt
import numpy as np

arr = np.linspace(-4, 4, 1000)
x, y = np.meshgrid(arr, arr)
z1 = np.sin((y**2 + (x - 2)**2))
z2 = np.sin((y**2 + (x + 2)**2))
plt.contourf(z1 + z2, cmap="gray")
plt.colorbar()
plt.show()

image.png

次に4点でやってみようと思います

import matplotlib.pyplot as plt
import numpy as np

arr = np.linspace(-4, 4, 1000)
x, y = np.meshgrid(arr, arr)
z1 = np.sin((y**2 + (x - 2)**2))
z2 = np.sin((y**2 + (x + 2)**2))
z3 = np.sin(((y - 2)**2 + x**2))
z4 = np.sin(((y + 2)**2 + x**2))
plt.contourf(z1 + z2 + z3 + z4, cmap="gray")
plt.colorbar()
plt.show()

image.png

まとめ

こういうの授業で見せてくれると想像しやすいんですけどね

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1