## 2020年4月28日火曜日

### 数学 - Python - 立体的な広がりの中の図形 - 空間図形 - 空間における点・直線・平面、空間の座標 - 2点間の距離 - 等距離、軸上の点、平面上の点、正三角形、連立方程式

1. 点 P を

$P\left(x,0,0\right)$

とおく。

$\begin{array}{l}AP=BP\\ \sqrt{{\left(x-1\right)}^{2}+1+1}=\sqrt{{\left(x+1\right)}^{2}+4}\\ {\left(x-1\right)}^{2}+2={\left(x+1\right)}^{2}+4\\ -2x+2=2x+4\\ x=-\frac{1}{2}\end{array}$

よって 求める x 軸上の点 P は

$P\left(-\frac{1}{2},0,0\right)$

2. 点 Q を

$Q\left(0,y,0\right)$

とおく。

$\begin{array}{l}AQ=BQ\\ \sqrt{1+{\left(y-1\right)}^{2}+1}=\sqrt{1+{y}^{2}+4}\\ -2y+3=5\\ y=-1\\ Q\left(0,-1,0\right)\end{array}$

ことから

$R\left(x,y,0\right)$

とおく。

$\begin{array}{l}A{B}^{2}\\ =4+1+9\\ =14\\ \left\{\begin{array}{l}{\left(x-1\right)}^{2}+{\left(y-1\right)}^{2}+1=14\\ {\left(x+1\right)}^{2}+{y}^{2}+4=14\end{array}\\ \left\{\begin{array}{l}{x}^{2}-2x+1+{y}^{2}-2y+1+1=14\\ {x}^{2}+2x+1+{y}^{2}+4=14\end{array}\\ \left\{\begin{array}{l}{x}^{2}-2x+{y}^{2}-2y=11\\ {x}^{2}+2x+{y}^{2}=9\end{array}\\ -4x-2y=2\\ y=-2x-1\\ {x}^{2}+2x+{\left(2x+1\right)}^{2}=9\\ 5{x}^{2}+6x-8=0\\ x=\frac{-3±\sqrt{9+40}}{5}\\ =\frac{-3±7}{5}\\ =-2,\frac{4}{5}\\ y=4-1=3\\ y=-\frac{8}{5}-1=-\frac{13}{5}\\ R\left(-2,3,0\right)\\ R\left(\frac{4}{5},-\frac{13}{5},0\right)\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, solve, Rational

print('6.')

x, y = symbols('x, y', real=True)
a = Matrix([1, 1, 1])
b = Matrix([-1, 0, -2])
ab = (a - b).norm()

class Test(TestCase):
def test1(self):
p = Matrix([x, 0, 0])
self.assertEqual(
solve((a - p).norm() - (b - p).norm()), [-Rational(1, 2)])

def test2(self):
r = Matrix([0, y, 0])
self.assertEqual(
solve((a - r).norm() - (b - r).norm()), [-1])

def test3(self):
r = Matrix([x, y, 0])
self.assertEqual(solve([(r - a).norm() - ab,
(r - b).norm() - ab]),
[{x: -2, y: 3},
{x: Rational(4, 5), y: -Rational(13, 5)}])

if __name__ == "__main__":
main()


% ./sample6.py -v
6.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok
test3 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.430s

OK
%