Write a program to find the number of triangles that can be formed with three different array elements as three sides of triangles, for a given unsort
Answers
Answer:
We consider the number of triangles formed by the intersecting diagonals of a regular polygon. Basic geometry provides a slight overcount, which is corrected by applying a result of Poonen and Rubinstein [1]. The number of triangles is 1, 8, 35, 110, 287, 632, 1302, 2400, 4257, 6956 for polygons with 3 through 12 sides.
Introduction
If we connect all vertices of a regular N-sided polygon we obtain a figure with = N (N - 1) / 2 lines. For N=8, the figure is:
Careful counting shows that there are 632 triangles in this eight sided figure.
Derivation
All triangles are formed by the intersection of three diagonals at three different points. There are five arrangements of three diagonals to consider. We classify them based on the number of distinct diagonal endpoints. We will directly count the number of triangles with 3, 4 and 5 endpoints (top three figures). We will count the number of potential triangles with 6 endpoints, then correct for the false triangles. In each of the following five figures, a sample triangle is highlighted.
Three, Four and Five Diagonal Endpoints
3 diagonal endpoints. There are 56 such triangles in the figure at left.
The number of triangles formed by diagonals with a total of three endpoints is simply.
4 diagonal endpoints. There are 280 such triangles in the figure at left.
There are combinations of the four diagonal endpoints. For each set of four endpoints, there are four triangle configurations. Thus there are triangles formed.
5 diagonal endpoints There are 280 such triangles in the figure at left.
For each of the N vertices of the polygon, there are four other diagonal endpoints which can be placed on the N-1 remaining locations. Thus there aretriangles formed. This is equal to .
Six diagonal endpoints
The number of potential triangles formed by 6 line segments is , since there are 6 segment endpoints to be chosen from a pool of N. Often potential triangles are not created by three overlapping line segments because the line segments intersect at a single point. counts both of the following two situations.
6 diagonal endpoints, resulting in triangle. There are 16 such triangles in the figure at left.
6 diagonal endpoints, false triangle. There are 9 interior intersection points in the figure at left where such false triangles can be formed.
We use a result of [1] to count these false triangles. As in that paper, for a regular N-sided polygon, let am(N) denote the number of interior points other than the center where m diagonals intersect. Surprisingly, only the values m = 2, 3, 4, 5, 6 or 7 may occur. The requisite formulae from [1] are reproduced here:
where if , 0 otherwise.
If there are K line segments that intersect at one common point, where K>2, there are false triangles corresponding to that point. Thus the correction term for false triangles is
where the last term represents the contribution of the center point for even N. The correction is 0 for odd N. The number of triangles formed by line segments with six endpoints on the polygon
Explanation:
six
There are six elements of a triangle, which are; three angles and three sides. Median: The line segment which joins a vertex of a triangle to the mid-point of its opposite side is called the median of the triangle. A triangle has three medians.six
There are six elements of a triangle, which are; three angles and three sides. Median: The line segment which joins a vertex of a triangle to the mid-point of its opposite side is called the median of the triangle. A triangle has three medians.