Klee's Algorithm (Length Of Union Of Segments of a line)Given starting and ending positions of segments on a line, the task is to take the union of all given segments and find length covered by these segments.Examples: Input : segments[] = {{2, 5}, {4, 8}, {9, 12}} Output : 9 Explanation: segment 1 = {2, 5} segment 2 = {4, 8} segment 3 = {9, 12} If we ta
9 min read
Count maximum points on same lineGiven N point on a 2D plane as pair of (x, y) co-ordinates, we need to find maximum number of point which lie on the same line. Examples: Input : points[] = {-1, 1}, {0, 0}, {1, 1}, {2, 2}, {3, 3}, {3, 4} Output : 4 Then maximum number of point which lie on same line are 4, those point are {0, 0}, {
10 min read
Minimum lines to cover all pointsGiven N points in 2-dimensional space, we need to print the count of the minimum number of lines which traverse through all these N points and which go through a specific (xO, yO) point also.Examples: If given points are (-1, 3), (4, 3), (2, 1), (-1, -2), (3, -3) and (xO, yO) point is (1, 0) i.e. ev
9 min read
Represent a given set of points by the best possible straight lineFind the value of m and c such that a straight line y = mx + c, best represents the equation of a given set of points (x_1 , y_1 ), (x_2 , y_2 ), (x_3 , y_3 ), ......., (x_n , y_n ), given n >=2. Examples: Input : n = 5 x_1 = 1, x_2 = 2, x_3 = 3, x_4 = 4, x_5 = 5y_1 = 14, y_2 = 27, y_3 = 40, y_4
10 min read
Program to find the mid-point of a lineGiven two coordinates of a line starting is (x1,y1) and ending is (x2,y2) find out the mid-point of a line. Examples : Input : x1 = â1, y1 = 2, x2 = 3, y2 = â6 Output : 1,â2 Input : x1 = 6.4, y1 = 3 x2 = â10.7, y2 = 4 Output : â2.15, 3.5 The Midpoint Formula: The midpoint of two points, (x1, y2) and
3 min read
Sum of Manhattan distances between all pairs of pointsGiven n integer coordinates. The task is to find the sum of the Manhattan distance between all pairs of coordinates. Manhattan Distance between (x1, y1) and (x2, y2) is: |x1 - x2| + |y1 - y2|Examples : Input : n = 4, p1 = { -1, 5 }, p2 = { 1, 6 }, p3 = { 3, 5 }, p4 = { 2, 3 }Output : 22Explanation :
9 min read
Program to check if three points are collinearGiven three points, check whether they lie on a straight (collinear) or notExamples : Input : (1, 1), (1, 4), (1, 5) Output : Yes The points lie on a straight line Input : (1, 5), (2, 5), (4, 6) Output : No The points do not lie on a straight line First approach Three points lie on the straight line
9 min read