Category Archives: Geometric

Count maximum points on same line

Given 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… Read More »

Area of a polygon with given n ordered vertices

Given ordered coordinates of a polygon with n vertices. Find area of the polygon. Here ordered mean that the coordinates are given either in clockwise manner or anticlockwise from first vertex to last. Examples: Input : X[] = {0, 4, 4, 0}, Y[] = {0, 0, 4, 4}; Output : 16 Input : X[] =… Read More »

Number of Integral Points between Two Points

Given two points p (x1, y1) and q (x2, y2), calculate the number of integral points lying on the line joining them. Example : If points are (0, 2) and (4, 0), then the number of integral points lying on it is only one and that is (2, 1). Similarly, if points are (1, 9)… Read More »

Count Integral points inside a Triangle

Given three non-collinear integral points in XY plane, find the number of integral points inside the triangle formed by the three points. (A point in XY plane is said to be integral/lattice point if both its co-ordinates are integral). Example: Input: p = (0, 0), q = (0, 5) and r = (5,0) Output: 6… Read More »

Orientation of 3 ordered points

Orientation of an ordered triplet of points in the plane can be counterclockwise clockwise colinear The following diagram shows different possible orientations of (a, b, c) If orientation of (p1, p2, p3) is collinear, then orientation of (p3, p2, p1) is also collinear. If orientation of (p1, p2, p3) is clockwise, then orientation of (p3,… Read More »

Find Simple Closed Path for a given set of points

Given a set of points, connect the dots without crossing. Example: Input: points[] = {(0, 3), (1, 1), (2, 2), (4, 4), (0, 0), (1, 2), (3, 1}, {3, 3}}; Output: Connecting points in following order would not cause any crossing {(0, 0), (3, 1), (1, 1), (2, 2), (3, 3), (4, 4), (1, 2),… Read More »