2020年7月5日日曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第12章(放物線・だ円・双曲線 - 2次関数)、12.1(放物線・だ円・双曲線)、だ円の問6の解答を求めてみる。


  1. 点 P、 Q、 R をそれぞれ

    P=(u,0)Q=(0,v)R=(x,y)

    とおく。

    R は PQ を

    1:2

    に内分する点なので

    (x,y)=(u,0)+2(0,v)2+1=(13u,23v)u=3x,v=32y

    また、線分 PQ の長さは6なので、

    u2+v2=6
    9x2+94y2=36
    x24+y216=1

    よって、 R の えがく軌跡は上の方程式の楕円。

コード

#!/usr/bin/env python3
import matplotlib.pyplot as plt
from matplotlib import animation
from sympy import sqrt

print('6.')

frames = 50
x0 = 12 / frames


def update(i: int, circle1, center2):
    u = -6 + x0 * (i + 1)
    v = sqrt(6 ** 2 - u ** 2)
    plt.plot([u, 0], [0, v])
    plt.plot([u, 0], [0, -v])
    x = u / 3
    y = 2 * v / 3
    circle1.center = x, y
    circle2.center = x, -y


fig = plt.gcf()
ax = plt.axes(xlim=(-6, 6), ylim=(-6, 6), aspect='equal')
circle1 = plt.Circle((-2, 0), 0.15)
circle2 = plt.Circle((-2, 0), 0.15)
ax.add_patch(circle1)
ax.add_patch(circle2)
plt.plot([-6, 0], [0, 0])
anim = animation.FuncAnimation(fig,
                               update,
                               fargs=(circle1, circle2),
                               frames=50,
                               interval=100,
                               repeat=True)
plt.show()
anim.save('sample6.gif', writer='imagemagick')

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample6.py 
6.
%

0 コメント:

コメントを投稿