2020年5月12日火曜日

学習環境

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



    1. AB=3,-2,4-2,0,1=1,-2,3AC=-1,2,0-2,0,1=-3,2,-1cosθ=AB·ACABAC=-3-4-31+4+99+4+1=-1014=-57

    2. S=12ABACsinθ=12·14·1-572=72-52=7+57-5=12·2=26

コード

#!/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 コメント:

コメントを投稿