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?

sympy「Triangle で指定した辺の長さを出力したい。」をAI先生に聞きました。

0
Last updated at Posted at 2026-02-06

(本日の)ChatGPT先生へ

1. sympy の Triangle で指定した辺の長さを出力したい。
2. T.sides[1] でいいですか。
3. それで
4. 1行は無理ですか。Triangle を2回使用以外にありませんか。
5. 上記の私の質問すべてから、Markdownのテキスト形式で、質問リストを出力して。追番を追加して。本質問も含めて。コピーできる形式で。空白行不要です。

(回答抜粋)

いい質問です。Triangle はちょっとクセがあるんですよね🙂
結論から言うと、Triangle そのものに「辺の長さを直接指定して取得するメソッド」はありません。
でも、頂点を使えば確実に出せます。...
なぜ T.sides[1] は使えないのか
これは list ではなく set です。
set の特徴
・順序が保証されない
・インデックスアクセス不可

from sympy import Point, Triangle

A = Point(0, 0)
B = Point(3, 0)
C = Point(0, 4)

T = Triangle(A, B, C)

# 各辺の長さ
AB = A.distance(B)
BC = B.distance(C)
CA = C.distance(A)

print("AB =", AB)
print("BC =", BC)
print("CA =", CA)

これ一択です。

A.distance(B)

❌ やらない方がいい書き方

T.sides[1]          # NG(set なので)
list(T.sides)[1]   # 非推奨(順序が保証されない)

Gemini先生へ

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

いつもと違うおすすめです。

sympy doc

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?