Tag Archives: triangle

Classify a triangle

We are given co-ordinates of a triangle. The task is to classify this triangle on basis of sides and angle. Examples: Input : p1 = (3, 0), p2 = (0, 4), p3 = (4, 7) Output : Right Angle triangle and Isosceles Input : p1 = (0, 0), p2 = (1, 1), p3 = (1,… 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 Triangles in Directed and Undirected Graphs

Given a Graph, count number of triangles in it. The graph is can be directed or undirected. Example: Input: digraph[V][V] = { {0, 0, 1, 0}, {1, 0, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 0} }; Output: 2 Give adjacency matrix represents following directed graph. We have discussed a method based on… 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 »

Number of Triangles in an Undirected Graph

Given an Undirected simple graph, We need to find how many triangles it can have. For example below graph have 2 triangles in it. Let A[][] be adjacency matrix representation of graph. If we calculate A3, then the number of triangle in Undirected Graph is equal to trace(A3) / 6. Where trace(A) is the sum… Read More »