天邪鬼的に修正天動説の動画GIFをコーディングしてみた
モチベーション
僕は生まれてこのかた、自分の感覚的に地動説が正しいと感じることがありません。この地球上にいる以上は天動説こそが真理に感じてしまいます。
ではなぜそれが正しくないということを知っているかというと、こちらのエントリにかかれているような科学の巨人達の肩の上にのって高等教育を受けさせてもらったことに他ならないのです。百聞は一見にしかずとは言いますが、目で見たことが正しいとも限らない、ということがあるのでなかなか難しいです。
一方で天動説を修正してみれば地球を中心とした正しい太陽系の図も作れるんですよね。ようはどこから観測するかの違いですもんね。地動説は神の視点でみたものですが、この修正天動説は地球上の観測者を固定して、より僕たちの実感に近いものになるはずです。
それ、Pythonでつくってみました
まずは地動説
ソースは後で掲載します。Jupyterコーディングしてアニメーションにしてみました。見やすさを考えて、太陽、水星、金星、地球、火星、月だけ。距離と速さは実際と同じ比率で設定していますが、月と地球の距離を実際比にするとあまりに地球に近くなるので実比よりだいぶ話しています。面倒なんで、月の公転速度も単純にして、太陽を回る地球の公転速度の1/12にしちゃいました。
まあ、見慣れていますよね。実にシンプル。念のため、真ん中が太陽で、内側から水、金、地、火の順に好転してます。地球の周りをまわっているのが月ですね。
続いて修正天動説
さて、地球を中心とするとどのようになるのでしょうか。。。
おお、なんかきしょくわるいっすね。真ん中が地球です。内側の円が月、外側が太陽になります。当然ほかの惑星は太陽の周りをまわっているんですね。
無理やりであることは承知の上ですが、こうした地球系のソーラーシステムというのも、閉じた宇宙空間では間違いではないと個人的に思うんですよね。もちろん、宇宙空間を説明するうえで、地動説がシンプルに働く、ということではあるのですが。
今回はJupyterの上で、Python2.7を使ってコーディングしました。まずは地動説のコード。超適当かつざっくり貼り付けます。
```python
import math
import matplotlib.pyplot as plt
import matplotlib.ticker
import matplotlib.animation as animation
%matplotlib inline
%matplotlib nbagg
class Planet():
def __init__(self, ax, sp, dm):
self.ax = ax
self.sp = sp
self.dm = dm
def diameter(self):
return self.dm
def axis(self, time=0):
if self.ax == 0:
return (0.0, 0.0)
else:
return Ear.position(time)
def position(self, time=0):
spd = 0.0
if self.sp != 0: spd = 1.0/self.sp
rd = time * 2*math.pi/10 * spd
if self.ax == 0:
return math.cos(rd) * self.dm, math.sin(rd) * self.dm
else:
x, y = Ear.position(time)
return x + math.cos(rd)* self.dm, y + math.sin(rd)*self.dm
Sun = Planet(0, 0.0, 0.0)
Mer = Planet(0, 0.24, 0.39)
Ven = Planet(0, 0.62, 0.72)
Ear = Planet(0, 1.0, 1.0)
Mar = Planet(0, 1.89, 1.5)
Moon = Planet(1, 0.083, 0.1)
plnt = [Sun, Mer, Ven, Ear, Mar, Moon]
fig = plt.figure()
ax = plt.axes(xlim=(-1.6, 1.6), ylim=(-1.6, 1.6))
ims =
for p in plnt:
if p.ax==0:
circle = plt.Circle( p.axis(0), p.diameter(), fill=False)
ax.add_artist(circle)
for i in range(300):
x, y = ,
for p in plnt:
px, py = p.position(i*0.1)
x.append(px)
y.append(py)
im = plt.plot(x, y, "bo")
ims.append(im)
ani = animation.ArtistAnimation(fig, ims, interval=100)
plt.show()
```
そして修正天動説。
```python
import math
import matplotlib.pyplot as plt
import matplotlib.ticker
import matplotlib.animation as animation
%matplotlib inline
%matplotlib nbagg
class Planet():
def __init__(self, ax, sp, dm):
self.ax = ax
self.sp = sp
self.dm = dm
def diameter(self):
return self.dm
def axis(self, time=0):
if self.ax == 0:
return (0.0, 0.0)
elif self.ax == 1:
return Sun.position(time)
else:
return Ear.position(time)
def position(self, time=0):
spd = 0.0
if self.sp != 0: spd = 1.0/self.sp
rd = time * 2*math.pi/10 * spd
if self.ax == 0:
return math.cos(rd) * self.dm, math.sin(rd) * self.dm
elif self.ax == 1:
x, y = Sun.position(time)
return x + math.cos(rd)* self.dm, y + math.sin(rd)*self.dm
else:
x, y = Ear.position(time)
return x + math.cos(rd)* self.dm, y + math.sin(rd)*self.dm
Sun = Planet(0, 1.0, 1.0)
Mer = Planet(1, 0.24, 0.39)
Ven = Planet(1, 0.62, 0.72)
Ear = Planet(0, 0.0, 0.0)
Mar = Planet(1, 1.89, 1.5)
Moon = Planet(0, 0.083, 0.1)
plnt = [Sun, Mer, Ven, Ear, Mar, Moon]
fig = plt.figure()
ax = plt.axes(xlim=(-2.0, 2.0), ylim=(-2.0, 2.0))
ims =
for p in plnt:
if p.ax==0:
circle = plt.Circle( p.axis(0), p.diameter(), fill=False)
ax.add_artist(circle)
for i in range(300):
x, y = ,
for p in plnt:
px, py = p.position(i*0.1)
x.append(px)
y.append(py)
im = plt.plot(x, y, "bo")
ims.append(im)
ani = animation.ArtistAnimation(fig, ims, interval=100)
plt.show()
```
その他メモ
動画GIFをつくるのに以下のサイトを参考にしました。
とても苦労したのは ffmpeg や ImageMagick のファイルパスを .matplotlibrc の設定ファイルに追加したのですが、クォーテーションでくくっているとダメなんですね。これを理解するのに6時間がかりでした。あー、無駄な時間を。。。