代码拉取完成,页面将自动刷新
obs =[]
def init_circular_obstacles(configNum=0):
global obs
obs.append(((0,0),50))
'''obs.append(((150,100),18))
obs.append(((150,130),18))
obs.append(((150,160),18))
obs.append(((150,190),18))
obs.append(((150,220),18))
obs.append(((150,250),18))
obs.append(((180,250),20))
obs.append(((210,250),20))
obs.append(((240,250),20))
obs.append(((270,250),20))
obs.append(((300,250),20))
obs.append(((330,250),20))
for circ in obs:
pygame.draw.circle(screen, black, circ[0], circ[1])'''
def lineCollides(p1, p2):
global obs
list = []
a = p2[1] - p1[1]
b = -(p2[0] - p1[0])
c = (-1*b * p2[1]) - (a * p2[0])
for circle in obs:
cen, rad = circle
val = (a * cen[0] + b * cen[1] + c*1.0) / (a * a + b * b);
#val = (a * cen[0] + b * cen[1] + c*1.0) / (a * a + b * b);
h = (val * a) + cen[0]
k = (val * b) + cen[1]
#pygame.draw.circle(screen, (255,255,0), (round(h),round(k)), 1)
if dist(cen,(h,k)) < rad:
return True
else:
t1 = (h - p1[0]) #/ (p2[0] - p1[0])
t2 = (k - p1[1]) #/ (p2[1] - p1[1])
if t1 * (p2[1] - p1[1]) != t2 * (p2[0] - p1[0]) and (t1 >= 0 and t1 <= (p2[0] - p1[0])):
#if t1 != t2 and t1 >= 0 and t1 <= 1:
return True
#list.append((h,k))
for i in list:
pygame.draw.circle(screen, (255,255,0), (round(i[0]),round(i[1])), 1)
return False
init_circular_obstacles()
while(True):
x1 = input()
y1 = input()
x2 = input()
y2 = input()
print(str(lineCollides((x1,y1),(x2,y2))))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。