Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import sympy.geometry as sg
- # 2点間の距離がrより大きいか小さいか調べる
- def dis_compare_r(p0, p1, r):
- dis = np.linalg.norm(p0 - p1)
- if dis >= r:
- return True
- else:
- return False
- # 点p1と点p2を結ぶ直線上のp1=(x1, y1)から同じ直線上で距離r離れた点を求める
- def other_p(p1, p2, r):
- center = sg.Point(p1[0], p1[1])
- radius = r
- circle = sg.Circle(center, radius)
- line = sg.Line(sg.Point(p1[0], p1[1]), sg.Point(p2[0], p2[1]))
- return sg.intersection(circle, line)
- if __name__ == '__main__':
- p0 = np.array([0, 0])
- p1 = np.array([1, 1])
- p2 = np.array([3, -3])
- r = 2**0.5
- p = other_p(p0, p2, r)
- print(p[0], p[1])
- next_p = np.array([2, 2])
- ans = dis_compare_r(next_p, p[0], r)
- print(ans)
- ans = dis_compare_r(next_p, p[1], r)
- print(ans)
Add Comment
Please, Sign In to add comment