Please tell me how to use python functions, arguments and return values. It would be helpful if you could tell us the recommended reference page. I think it will be shorter. Thank you.
"Only when they are far apart ... 4 tangents" By the way, the following program calculates only one The size of r1r2 may be relevant. It is assumed that r1 <r2.
(Reference) Find the common tangent of two circles https://qiita.com/tydesign/items/0100c49c6335695e6990
#[Example] Center(10,12)Radius 2 and center(50,42)Find the common tangent of a circle with a radius of 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}))#
Omitted in the middle of the result 10 10 50 10
Recommended Posts