Find the intersections

0

0 votes
Line segment, Medium, Geometry, Line Sweep Technique, Implementation, Line Intersection using Bentley Ottmann Algorithm, Algorithms, Mathematics, Mathematics
Problem

You are given a set of N line segments that are either horizontal or vertical. Write a program to determine the points of intersection of all the horizontal line segments with the vertical line segments.

Note: Do not consider the coincident endpoints as intersections.

Input format

  • First line: N
  • Next N lines: Four space-separated integers, x1, y1, x2, and y2 denoting the coordinates of two line segments

Output format

Sort and print all the intersection points of the horizontal and the vertical line segments. The intersection point is represented as (x, y) with space between them.

Constraints

1N103

For horizontal line:

1x1<x2106
1y1=y2106

For vertical line:

1x1=x2106
1y1<y2106

Sample Input
3
1 2 4 2
2 1 2 3
3 1 3 3
Sample Output
2 2
3 2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The intersections are (2,2) and (3,2)

Contributers:
Editor Image

?