1 | initial version |
I understand that you need two things:
1. Intersection detection
Let v1
and v2
be the points that desribe the ends of a vertical line and d1 and d2 be analogical points of a diagonal one. Also let's assume v1.y > v2.y
and d1.y > d2.y
. Intersection takes place if v1.y > d2.y
and in the same time v2.y < d1.y
.
So, for each vertical line you check, you should determine which point has greater Y (i.e. vertical) coordinate, do the same for the diagonal one, and then do the check as described above.
2. Finding intersection point
You need to find lines equation, which is trivial since you have two points of the diagonal line and in case of vertical line equation is just x = d1.x . Put d1.x into diagonal line equation to find the intersection point.
When you have it, just replace the Y coordinate of your vertical line with the Y coordinate of the intersection point. Voila - your vertical line ends at the point of intersection with the diagonal line now.