line_end_x = line_start_x + cos(angle)*line_length
line_end_y = line_start_y + sin(angle)*line_length
if your line crosses the vertical edge:
intersection_x = edge_x
intersection_y = line_start_y + (intersection_x - line_start_x) * tan(angle)
if your line crosses the horizontal edge:
intersection_y = edge_y
intersection_x = line_start_x + (intersection_y - line_start_y) * tan(angle-pi/4)
EDIT: fixed
source
share