Reputation: 4771
I have two segments. Every segment will be either vertical or horizontal (0°, 90°, 180°, 270°). I need to find intersection point of these two segments. I need also calculate the intersection point if both segments are vertical or horizontal. Thank you.
Upvotes: 0
Views: 310
Reputation: 1087
There are 2 point P1[(x1,y1),(x2,y2)] and P2[(x1,y1),(x2,y2)].
Since the lines are either horizontal or vertical, one line will have a x constant and the other has a y constant.
So for each point check if x1 = x2 and it true make x = x1. Similarly if y1=y2, make y = y2. (x,y) is your intersection point.
If either x or y remains null at the end, then it means the lines are parallel hence no intersection. (If lines are parallel, the same variable will vary)
Upvotes: 1