Minimum area of a Polygon with three points given
Given three points of a regular polygon(n > 3), find the minimum area of a regular polygon (all sides same) possible with the points given.
Input : 0.00 0.00 1.00 1.00 0.00 1.00 Output : 1.00 By taking point (1.00, 0.00) square is formed of side 1.0 so area = 1.00 .
One thing to note in question before we proceed is that the number of sides must be at least 4 (note n > 3 condition)..
Here, we have to find the minimum area possible for a regular polygon, so to calculate the minimum possible area, we need to calculate the required value of n. As the side length is not given, so we first calculate the circumradius of the triangle formed by the points. It is given by the formula
R = abc / 4A
Where a, b, c are the sides of the triangle formed and A is the area of the triangle. Here, the area of the triangle can be calculated by Heron’s Formula.
After calculating circumradius of the triangle, we calculate the area of the polygon by the formula
A = nX ( sin(360/n) xr2 /2 )
Here r represents the circumradius of n-gon (regular polygon of n sides).
But, first we have to calculate value of n . To calculate n we first have to calculate all the angles of triangle by the cosine formula
cosA = ( b2+c2-a2 ) / 2bc
cosB = ( a2+c2-b2 ) / 2ac
cosC = ( a2+b2-c2 ) / 2ab
Then, n is given by
n = pi / GCD (A , B, C )
Where A, B and C are the angles of the triangle . After calculating n we substitute this value to the formula for calculating area of polygon .
Below is the implementation of the given approach :
Time complexity : O(log(min(A,B,C)))
Auxiliary Space : O(1), since no extra space has been taken.