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?

More than 3 years have passed since last update.

2つの円の共通接線の接点を求める(sympyの行列)

Posted at

pythonの関数、引数、戻り値の使い方を教えて下さい。
おすすめの参考のページを教えてもらうと助かります。
もっと短くなると、思います。
よろしくお願いします。

「離れている場合のみ      ・・・ 接線は4本」
のところ、以下のプログラムは、1本のみ計算
r1r2の大小が関係するかもしれません。r1<r2を想定しています。

(参考)2つの円の共通接線を求める
https://qiita.com/tydesign/items/0100c49c6335695e6990


# 【例】中心(10,12) 半径2と中心(50,42) 半径30の円の共通接線を求める																													
from sympy import *																													
var('x1 y1 r1 x2 y2 r2 tx ty co si sx1 sy1 sx2 sy2')																													
sx1=0																													
sy1=r1																													
sx2=sqrt((x1-x2)**2+(y1-y2)**2-(r2-r1)**2)																													
sy2=r2																													
v=solve([co*sx1-si*sy1+tx-x1,																													
              si*sx1+co*sy1+ty-y1,																													
              co*sx2-si*sy2+tx-x2,																													
              si*sx2+co*sy2+ty-y2],																													
             [co,si,tx,ty])																													
A=Matrix([																													
           [v[co],-v[si],v[tx]],																													
           [v[si], v[co],v[ty]],																													
           [    0,       0,    1]																													
])																													
B=Matrix([																													
          [sx2],																													
          [  0] ,																													
          [  1]																													
])																													
AB=A*B																													
print("---------------------------------------")																													
print(tx)																													
print(ty)																													
print(AB[0])																													
print(AB[1])																													
print("---------------------------------------")																													
print(v[tx].subs({x1:10,y1:12,r1:2,x2:50,y2:42,r2:32}),																													
v[ty].subs({x1:10,y1:12,r1:2,x2:50,y2:42,r2:32}))																													
print(AB[0].subs({x1:10,y1:12,r1:2,x2:50,y2:42,r2:32}),																													
AB[1].subs({x1:10,y1:12,r1:2,x2:50,y2:42,r2:32}))#

結果途中省略
10 10
50 10

接線の方程式は(未)

classでintersectionの方法が早い気がしてきました。(未)

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?