Given lines represented by two points and . The task is to find maximum number of lines which can pass through a single point, without superimposing (or covering) any other line. We can move any line but not rotate it.
Input : Line 1 : x1 = 1, y1 = 1, x2 = 2, y2 = 2 Line 2 : x2 = 2, y1 = 2, x2 = 4, y2 = 10 Output : 2 There are two lines. These two lines are not parallel, so both of them will pass through a single point. Input : Line 1 : x1 = 1, y1 = 5, x2 = 1, y2 = 10 Line 2 : x2 = 5, y1 = 1, x2 = 10, y2 = 1 Output : 2
- Represent lines as pair where line can be given as , called line slope form. We can now see that we can change the c for any line, but cannot modify m.
- Lines having same value of m parallel, given that (c1 ≠ c2). Also no two parallel lines can pass through same point without superimposing to each other.
- So, our problem reduces to finding different values of slopes from given set of lines.
We can calculate slope of a line as , add them to a set and count the number of distinct values of slope in set. But we have to handle vertical lines separately.
So, if then, slope = INT_MAX.
Otherwise, slope = .
Below is the implementation of the approach.
- Program for Point of Intersection of Two Lines
- Count number of pairs of lines intersecting at a Point
- Find intersection point of lines inside a section
- Integers from the range that are composed of a single distinct digit
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Maximum points of intersection n lines
- Maximum number of region in which N non-parallel lines can divide a plane
- Maximum of sum and product of digits until number is reduced to a single digit
- Maximum sum of distinct numbers with LCM as N
- Maximum number of distinct positive integers that can be used to represent N
- Reflection of a point at 180 degree rotation of another point
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Rotation of a point about another point in C++
- Program to find line passing through 2 Points
- Find X and Y intercepts of a line passing through the given points
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.