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?

円周角「一辺が固定されていて、対角45°の軌跡を知りたい。」をsympyでAI先生に教えてもらいました。

0
Posted at

(本日の)Gemini先生へ

一辺が固定されていて、対角45°の軌跡を知りたい。

(途中省略。最後だけ)

# SymPyのGeometryモジュールのCircleオブジェクトを返す関数

import sympy as sp
from sympy.geometry import Point, Circle

def get_locus_circle(A=(0, 0), B=(1, 0), angle_deg=45):
    """
    固定された2点 A, B に対し、上側の円周角が angle_deg となる軌跡の円(Circleオブジェクト)を返します。
    """
    pA = Point(A)
    pB = Point(B)
    
    # 線分ABの中点 M と 長さ L
    M = pA.midpoint(pB)
    L = pA.distance(pB)
    
    # ベクトル AB の方向角
    dx = float(pB.x - pA.x)
    dy = float(pB.y - pA.y)
    theta_ab = sp.atan2(dy, dx)
    
    # 中点から中心までの距離 d = (L / 2) * cot(θ)
    d = (L / 2) * sp.cot(sp.rad(angle_deg))
    
    # 垂直上方向(+90度回転)の単位ベクトル方向へ d 進んだ位置が中心座標 O
    center_x = M.x - d * sp.sin(theta_ab)
    center_y = M.y + d * sp.cos(theta_ab)
    center = Point(sp.simplify(center_x), sp.simplify(center_y))
    
    # 半径 R = (L / 2) / sin(θ)
    radius = sp.simplify((L / 2) / sp.sin(sp.rad(angle_deg)))
    
    return Circle(center, radius)

# 実行例
circle_obj = get_locus_circle((0, 0), (1, 0), 45)
print("SymPy Circle:", circle_obj)
print("中心座標    :", circle_obj.center)
print("半径        :", circle_obj.radius)
print("方程式      :", circle_obj.equation())

実行結果

SymPy Circle: Circle(Point2D(1/2, 1/2), sqrt(2)/2)
中心座標    : Point2D(1/2, 1/2)
半径        : sqrt(2)/2
方程式      : (x - 1/2)**2 + (y - 1/2)**2 - 1/2

履歴

1. 一辺が固定されていて、対角45°の軌跡を知りたい。
2. 上記のsympyのユーザー定義関数を教えて下さい。
3. 上側のみで、引数は2点の座標と円周角のみでお願いします。
4. 戻り値は、sympyのcircleで
5. 結果もお願いします。
6. 上記の私の質問すべてから、Markdownのテキスト形式で、質問リストを出力して。追番を追加して。本質問も含めて。コピーできる形式で。空白行不要です。

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

wikipedia

Qiita内

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?