Guest User

Untitled

a guest
May 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import sympy.geometry as sg
  4.  
  5. # 2点間の距離がrより大きいか小さいか調べる
  6. def dis_compare_r(p0, p1, r):
  7. dis = np.linalg.norm(p0 - p1)
  8. if dis >= r:
  9. return True
  10. else:
  11. return False
  12.  
  13.  
  14. # 点p1と点p2を結ぶ直線上のp1=(x1, y1)から同じ直線上で距離r離れた点を求める
  15. def other_p(p1, p2, r):
  16. center = sg.Point(p1[0], p1[1])
  17. radius = r
  18.  
  19. circle = sg.Circle(center, radius)
  20. line = sg.Line(sg.Point(p1[0], p1[1]), sg.Point(p2[0], p2[1]))
  21. return sg.intersection(circle, line)
  22.  
  23. if __name__ == '__main__':
  24. p0 = np.array([0, 0])
  25. p1 = np.array([1, 1])
  26. p2 = np.array([3, -3])
  27. r = 2**0.5
  28.  
  29. p = other_p(p0, p2, r)
  30. print(p[0], p[1])
  31.  
  32. next_p = np.array([2, 2])
  33. ans = dis_compare_r(next_p, p[0], r)
  34. print(ans)
  35. ans = dis_compare_r(next_p, p[1], r)
  36. print(ans)
Add Comment
Please, Sign In to add comment