Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Shooting range solution in Uncategorized category for Shooting Range by capback250
from math import atan2, degrees, sqrt, sin, radians
def angle_(p1, p2):
return degrees(atan2(p2[1] - p1[1], p2[0] - p1[0]))
def shot(wall1, wall2, shot_point, in_time):
angle1 = angle_(wall1, wall2) - angle_(wall1, shot_point)
angle2 = angle_(in_time, shot_point) - angle_(wall1, shot_point)
if (angle1 > 0 and angle2 > 0) or (angle1 < 0 and angle2 < 0):
return -1
angle1 = abs(angle1)
angle2 = abs(angle2)
if angle1 > 180:
angle1 = abs(180 - angle1)
if angle2 > 180:
angle2 = abs(180 - angle2)
angle3 = 180 - angle1 - angle2
katet3 = sqrt((wall1[0] - shot_point[0]) ** 2 + (wall1[1] - shot_point[1]) ** 2)
katet2 = katet3 / sin(radians(angle3)) * sin(radians(angle2))
wall = sqrt((wall1[0] - wall2[0]) ** 2 + (wall1[1] - wall2[1]) ** 2)
if katet2 == wall or katet2 == 0:
return 0
elif katet2 > wall or katet2 < 0:
return -1
else:
return 100 - int(round(abs(wall / 2 - katet2) / (wall / 2) * 100))
Aug. 25, 2015