2020年5月12日火曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第11章(立体的な広がりの中の図形 - 空間図形)、11.2(空間のベクトル)、ベクトルの内積の問14の解答を求めてみる。



    1. A B = 3 , - 2 , 4 - 2 , 0 , 1 = 1 , - 2 , 3 A C = - 1 , 2 , 0 - 2 , 0 , 1 = - 3 , 2 , - 1 cos θ = A B · A C A B A C = - 3 - 4 - 3 1 + 4 + 9 9 + 4 + 1 = - 10 14 = - 5 7

    2. S = 1 2 A B A C sin θ = 1 2 · 14 · 1 - 5 7 2 = 7 2 - 5 2 = 7 + 5 7 - 5 = 12 · 2 = 2 6

コード

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

print('14.')

a = Matrix([2, 0, 1])
b = Matrix([3, -2, 4])
c = Matrix([-1, 2, 0])
ab = b - a
ac = c - a
cos_theta = ab.dot(ac) / (ab.norm() * ac.norm())


class TestTriangle(TestCase):
    def test1(self):
        self.assertEqual(cos_theta, -Rational(5, 7))

    def test2(self):
        sin_theta = sqrt(1 - cos_theta ** 2)
        self.assertEqual(ab.norm() * ac.norm() * sin_theta / 2, 2 * sqrt(6))


t = symbols('t')
p = plot3d_parametric_line(*[(*(o + t * q), (t, 0, 1))
                             for (o, q) in [(a, ab), (a, ac), (b, (c - b))]],
                           legend=True,
                           show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
    o.line_color = color


p.save('sample14.png')
p.show()

if __name__ == "__main__":
    main()

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

% ./sample14.py -v
14.
test1 (__main__.TestTriangle) ... ok
test2 (__main__.TestTriangle) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.003s

OK
%

0 コメント:

コメントを投稿