How to get points X, Y coordinates from a linear angle?

So I have an 8x8 square. It has a line.

Line size == 8 angle == 0. 

One of the points of the line is always at one of the upper corners.

What will be the formula for obtaining the coordinates of the points where the line intersects the borders of the square? (a positive angle means that one of the points on the line is 0, 0. a negative 0, 8)

What will be the mathematical formula for each coordinate point? (if possible, pseudo-code)

+3
source share
1 answer
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

+6
source

Source: https://habr.com/ru/post/1790592/