LoginSignup
0
2

More than 5 years have passed since last update.

方べきの定理をだいたいsympyを使って解く

Last updated at Posted at 2017-04-24

(参考)方べきの定理(方冪の定理、ほうべきのていり)
https://ja.wikipedia.org/wiki/%E6%96%B9%E3%81%B9%E3%81%8D%E3%81%AE%E5%AE%9A%E7%90%86
https://en.wikipedia.org/wiki/Intersecting_chords_theorem
r,角度に値を入力しています。

from sympy import *
var('r tA tB tC tD')
def fnoKeisan(AA,BB,CC,DD):
    P = Line(AA, BB).intersection(Line(CC, DD))
    f = P[0].distance(A) *  P[0].distance(B) - P[0].distance(C) * P[0].distance(D)
    return f
print('図1-------------------------------------')
r=1000
tA = pi / 180 * (135)
tB = pi / 180 * (315)
tC = pi / 180 * (225)
tD = pi / 180 * ( 45)
A = Point(r * cos(tA), r * sin(tA))
B = Point(r * cos(tB), r * sin(tB))
C = Point(r * cos(tC), r * sin(tC))
D = Point(r * cos(tD), r * sin(tD))
print('#PA・PB-PC・PD=',fnoKeisan(A,B,C,D))
print('#PA・PB-PC・PD=',float(fnoKeisan(A,B,C,D)))
print('図2-------------------------------------')
r=1000
tA = pi / 180 * (175)
tB = pi / 180 * (10)
tC = pi / 180 * (190)
tD = pi / 180 * (315)
A = Point(r * cos(tA), r * sin(tA))
B = Point(r * cos(tB), r * sin(tB))
C = Point(r * cos(tC), r * sin(tC))
D = Point(r * cos(tD), r * sin(tD))
print('#PA・PB-PC・PD=',fnoKeisan(A,B,C,D))
print('#PA・PB-PC・PD=',float(fnoKeisan(A,B,C,D)))

#PA・PB-PC・PD= 0
#PA・PB-PC・PD= 0.0
-------------------------------------------------
#PA・PB-PC・PD= -sqrt((500*(-2*s.....つづく......
#PA・PB-PC・PD= 2.4784588255035637e-119
0
2
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
2