## 2020年6月4日木曜日

### 数学 - Python - 立体的な広がりの中の図形 - 空間図形 - 直線・平面・球の方程式 - 平面の方程式 - 直線と平面の交点、媒介変数表示

1. 2点

$\left(1,2,3\right),\left(3,1,-5\right)$

を通る直線の方程式を求める。

$\left(x,y,z\right)=\left(1,2,3\right)+t\left(2,-1,-8\right)$

xy 平面と の交点の z 座標.は0なので

$\begin{array}{l}3-8t=0\\ t=\frac{3}{8}\end{array}$

よって、求める交点の座標_は

$\begin{array}{l}\left(1,2,3\right)+\frac{3}{8}\left(2,-1,-8\right)\\ =\left(1,2,3\right)+\left(\frac{3}{4},-\frac{3}{8},-3\right)\\ =\left(\frac{7}{4},\frac{13}{8},0\right)\end{array}$

2. $\begin{array}{l}2-t=0\\ t=2\end{array}$
$\begin{array}{l}\left(1,2,3\right)+2\left(2,-1,-8\right)\\ =\left(5,0,-13\right)\end{array}$

3. $\begin{array}{l}\left(x,y,z\right)=\left(-1,2,3\right)+t\left(4,0,7\right)\\ =\left(-1+4t,2,3+7t\right)\end{array}$
$\begin{array}{l}\left(-1+4t\right)-4·2+4\left(3+7t\right)=19\\ 32t=16\\ t=\frac{1}{2}\end{array}$
$\left(-1+2,2,3+\frac{7}{2}\right)=\left(1,2,\frac{13}{2}\right)$

4. $\begin{array}{l}x=1+t\\ y=-1+4t\\ z=-2-t\end{array}$
$\begin{array}{l}2+2t-2+8t-2-t=7\\ 9t=9\\ t=1\end{array}$
$\left(2,3,-3\right)$

コード

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

print('30.')

ls = [Matrix([1, 2, 3]) + t * (Matrix([3, 1, -5]) - Matrix([1, 2, 3])),
Matrix([-1, 2, 3]) + t * Matrix([4, 0, 7]),
Matrix([1, -1, -2]) + t * Matrix([1, 4, -1])]

class Test(TestCase):
def test1(self):
t0 = solve(ls[0][2], t)[0]
self.assertEqual(ls[0].subs({t: t0}),
Matrix([Rational(7, 4), Rational(13, 8), 0]))

def test2(self):
t0 = solve(ls[0][1], t)[0]
self.assertEqual(ls[0].subs({t: t0}),
Matrix([5, 0, -13]))

def test3(self):
t0 = solve(
(x - 4 * y + 4 * z - 19).subs(dict(zip([x, y, z], ls[1]))))[0]
self.assertEqual(ls[1].subs({t: t0}),
Matrix([1, 2, Rational(13, 2)]))

def test4(self):
t0 = solve(
(2 * x + 2 * y + z - 7).subs({x: 1 + t, y: -1 + 4 * t, z: -2 - t}))[0]
self.assertEqual(ls[2].subs({t: t0}),
Matrix([2, 3, -3]))

if __name__ == "__main__":
main()


% ./sample30.py -v
30.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok
test3 (__main__.Test) ... ok
test4 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.019s

OK
%