Given a rectangle on 2D plane `$((0,0),(a,b))`$ where `$2 <=\leq a,b <=\leq 1000`$, two different points of me and another person `$(x_1, y_1) !=\neq (x_2, y_2)`$ such that `$x_1,y_1,x_2,y_2$ are integers, $0 < x_1,x_2 < a` and `$, $0 < y_1,y_2 < b`$, and `d`$d$ — the range of our gun where `$2 <= d <=\leq d \leq 10000`$, find how many angles we can shoot at so that the bullet hits the other person and traveled at most a distance `d`.↵
↵
Shooting another person means that after the bullet goes in one direction, reflects geometrically against the walls, and repeating those actions, it hits the other person.$d$.↵
↵
When the bullet hits the wall it geometrically reflects against it, and if it hits the corner it bounces back.↵
↵
Shooting another person means that the first person the bullet hits is the other person and not me, and the distance traveled by the bullet is at most $d$.↵
↵
My solution right now is kind of reflect all the points over each of the walls, then do it over and over. Due to the constraints, it enough to reflect the points in each direction $5000$ times. So in total, for directions it would give me somewhat around $(2 \cdot 5000)^2 \cdot 2 = 2 \cdot 10^8$ points. Afterward, I sort the points by the angle relative to $(x_1, y_1)$ and just go in that order, making sure the distance between me and the point of interest is at most $d$ and that there are no other points between us (that's what I sorted).↵
↵
Now this is slow since there are many points, I just thought maybe there are some other solutions?
↵
Shooting another person means that after the bullet goes in one direction, reflects geometrically against the walls, and repeating those actions, it hits the other person.
↵
When the bullet hits the wall it geometrically reflects against it, and if it hits the corner it bounces back.↵
↵
Shooting another person means that the first person the bullet hits is the other person and not me, and the distance traveled by the bullet is at most $d$.↵
↵
My solution right now is kind of reflect all the points over each of the walls, then do it over and over. Due to the constraints, it enough to reflect the points in each direction $5000$ times. So in total, for directions it would give me somewhat around $(2 \cdot 5000)^2 \cdot 2 = 2 \cdot 10^8$ points. Afterward, I sort the points by the angle relative to $(x_1, y_1)$ and just go in that order, making sure the distance between me and the point of interest is at most $d$ and that there are no other points between us (that's what I sorted).↵
↵
Now this is slow since there are many points, I just thought maybe there are some other solutions?