0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

メネラウスの定理。大人用「2024 青森公立大学前期【4】」(その4/4)をsympyのいつもの方法でできませんでした。ChatGPT先生へ。

Last updated at Posted at 2025-11-09

(その1/4)
(その2/4)
(その3/4)
(その4/4) 本ページ

・Triangleでした。
・メネラウスの定理は使っていませんが、タイトルはそのままです。

できませんでした。sympyで(いつもの方法で)

ver4.0

・60°を変数で、できませんでした。 θ_deg=60は、ver3.0でOKです。

# ver4.0
from sympy import *
# θ_deg=60
var('θ_deg',real=True, positive=True)
AB,CA=8,5
AD,CE=3,2
trABC=Triangle(sas=(CA,θ_deg,AB))                #;print(trABC)
BC   =trABC.args[1].distance(trABC.args[2])      #;print(BC)
trBCA=Triangle(sss=(BC,CA,AB))                   #;print(trBCA)
A,B,C=trBCA.args[2],trBCA.args[0],trBCA.args[1]
D    =A+AD*(B-A).unit
E    =C+CE*(A-C).unit
P    =Line(B,E).intersection(Line(C,D))[0]       #;print(P)
F    =Line(A,P).intersection(Line(B,C))[0]       #;print(F)
print("#",A.distance(P)/P.distance(F))
print("#",abs(Triangle(D,E,F).area))
#
# Traceback (most recent call last):
#   File "/home/xx/yy.py", line zz, in <module>
#     A,B,C=trBCA.args[2],trBCA.args[0],trBCA.args[1]
#           ^^^^^^^^^^
# AttributeError: 'NoneType' object has no attribute 'args'

原因:(本日の)ChatGPT先生へ

質問

# ver3.0
(ソースコードの省略)

上はエラーがでませんが、下は、AttributeError: 'NoneType'のエラーがでます。どうしてですか?どのように修正したらいいですか?

# ver3.0
(ソースコードの省略)

回答

(回答抜粋)

🔍 原因の概要

ver4.0 では、θ_deg を数値ではなく 未定義のシンボル変数 として宣言しているため、
trABC = Triangle(sas=(CA, θ_deg, AB))

の段階で、Sympy は 具体的な三角形の点座標を決定できません。
そのため Triangle(...) は 三角形オブジェクトではなく None を返す 場合があります。
...

原因:(本日の)Gemini先生へ

同じ質問

回答

(回答抜粋)

...
SymPyの Triangle クラスは、sss (3辺の長さ) で三角形を作成する場合、
すべての辺の長さが具体的な数値であるか、あるいはシンボリックでも3つの辺の長さが与えられた場合に、
三角形の形状が定義できることが期待されます。
...

・ここまでです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?