## 2020年5月9日土曜日

### 数学 - Python - 立体的な広がりの中の図形 - 空間図形 - 空間のベクトル - ベクトルの内積 - 立方体、辺、対角線、長さ、三角関数9余弦)

1. $\begin{array}{l}\stackrel{\to }{AB}·\stackrel{\to }{AF}\\ =1·\sqrt{2}\mathrm{cos}\frac{\pi }{4}\\ =1\end{array}$

2. $\sqrt{2}·\sqrt{2}·\mathrm{cos}\frac{\pi }{3}=1$

3. $\sqrt{2}·\sqrt{2}·\mathrm{cos}\frac{\pi }{2}=0$

4. $\sqrt{2}·\sqrt{2}\mathrm{cos}\pi =-2$

5. $\sqrt{3}·\sqrt{2}·\frac{\sqrt{2}}{\sqrt{3}}=2$

6. $1$

7. $\frac{\sqrt{3}}{2}·\sqrt{2}·\frac{\sqrt{2}}{\sqrt{3}}=1$

8. $\frac{\sqrt{2}}{2}·\sqrt{2}\mathrm{cos}\frac{2}{3}\pi =-\frac{1}{2}$

9. $0$

コード

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

print('12.')

class TestVector(TestCase):
def test(self):
a = Matrix([0, 0, 0])
b = Matrix([0, 0, 1])
c = Matrix([1, 0, 1])
d = Matrix([1, 0, 0])
e = Matrix([0, 1, 0])
f = Matrix([0, 1, 1])
g = Matrix([1, 1, 1])
h = Matrix([1, 1, 0])
p = (g - a) / 2
q = (c + h) / 2
s = [b.dot(f),
f.dot(g - b),
(g - b).dot(e - d),
(e - d).dot(c - f),
(e - c).dot(f - c),
(d - a).dot(c - b),
(p - e).dot(d - e),
(q - c).dot(d - e),
(p - a).dot(q - c)]
t = [1, 1, 0, -2, 2, 1, 1, -Rational(1, 2), 0]
for i, (s0, t0) in enumerate(zip(s, t), 1):
print(f'({i})')
self.assertEqual(s0, t0)

if __name__ == "__main__":
main()


% ./sample12.py -v
12.
test (__main__.TestVector) ... (1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
ok

----------------------------------------------------------------------
Ran 1 test in 0.037s

OK
%