2020年6月23日火曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第11章(立体的な広がりの中の図形 - 空間図形)、11.3(直線・平面・球の方程式)、球面と平面の問44の解答を求めてみる。


  1. ( - 3 + 2 t ) 2 + ( 2 - t ) 2 + ( - 5 + 2 t ) 2 = 38
    4 t 2 - 12 t + 9 + t 2 - 4 t + 4 + 4 t 2 - 20 t + 25 = 38
    9 t 2 - 36 t = 0
    t ( t - 4 ) = 0
    t = 0 , 4

    よって、 問題の直線と球面の交点の座標は、

    ( - 3 , 2 , - 5 ) , ( 5 , - 2 , 3 )

    接平面の方程式はそれぞれ

    - 3 x + 2 y - 5 z = 38 5 x - 2 y + 3 z = 38

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import solve, Matrix
from sympy.plotting import plot3d, plot3d_parametric_line
from sympy.abc import t, x, y, z

print('44.')

lx = -3 + 2 * t
ly = 2 - t
lz = -5 + 2 * t
eq = x ** 2 + y ** 2 + z ** 2 - 38


class Test(TestCase):
    def test(self):
        ts = solve(eq.subs({x: lx, y: ly, z: lz}))
        self.assertEqual(
            sorted([Matrix([lx, ly, lz]).subs({t: t0})
                    for t0 in ts],
                   key=lambda x: x[0]),
            [Matrix([-3, 2, -5]),
             Matrix([5, -2, 3])]
        )


zs = solve(eq, z)
for i, f in enumerate([(-3 * x + 2 * y - 38) / 5,
                       (-5 * x + 2 * y + 38) / 3]):
    p = plot3d(*zs, f,
               (x, -10, 10),
               (y, -10, 10),
               show=False)
    p.append(plot3d_parametric_line(lx, ly, lz, show=False)[0])
    p.save(f'sample44_{i}.png')
p.show()

if __name__ == "__main__":
    main()

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

% ./sample44.py -v
44.
test (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.025s

OK
%

0 コメント:

コメントを投稿