<script>
// Javascript program to find minimum
// area of polygon of number of
// sides more than three with
// given three points.
// Assigning pi value to variable
let pi = 3.14159265359;
function fmod(a, b) {
let result = Math.floor(a / b);
return a - result * b;
}
// calculating gcd value of
// two double values .
function gcd(x, y) {
return Math.abs(y) < 1e-4 ? x :
gcd(y, fmod(x, y));
}
// Calculating minimum area of polygon through this function .
function min_area_of_polygon(Ax, Ay, Bx, By, Cx, Cy) {
let a, b, c, Radius, Angle_A, Angle_B, Angle_C,
semiperimeter, n, area;
// Calculating the length of the sides
// of the triangle formed from given
/// points a, b, c represents the
// length of different sides of triangle .
a = Math.sqrt((Bx - Cx) * (Bx - Cx) +
(By - Cy) * (By - Cy));
b = Math.sqrt((Ax - Cx) * (Ax - Cx) +
(Ay - Cy) * (Ay - Cy));
c = Math.sqrt((Ax - Bx) * (Ax - Bx) +
(Ay - By) * (Ay - By));
// Here we have calculated the
// semiperimeter of a triangle .
semiperimeter = (a + b + c) / 2;
// Now from the semiperimeter area
// of triangle is derived
// through the heron's formula .
let area_triangle = Math.sqrt(semiperimeter *
(semiperimeter - a) *
(semiperimeter - b) *
(semiperimeter - c));
// Thus circumradius of the triangle
// is derived from the sides and
// area of the triangle calculated .
Radius = (a * b * c) / (4 * area_triangle);
// Now each angle of the triangle
// is derived from the sides
// of the triangle .
Angle_A = Math.acos((b * b + c * c - a * a) /
(2 * b * c));
Angle_B = Math.acos((a * a + c * c - b * b) /
(2 * a * c));
Angle_C = Math.acos((b * b + a * a - c * c) /
(2 * b * a));
// Now n is calculated such that
// area is minimum for the regular n-gon .
n = pi / gcd(gcd(Angle_A, Angle_B), Angle_C);
// calculating area of regular n-gon
// through the circumradius of the triangle .
area = (n * Radius * Radius *
Math.sin((2 * pi) / n)) / 2;
return area;
}
function to_fixed(float, pre) {
let x = new String(float).split(".")
return x[0] + "." + x[1].slice(0, pre)
}
// Driver code
// Three points are given as input .
let Ax, Ay, Bx, By, Cx, Cy;
Ax = 0.00;
Ay = 0.00;
Bx = 1.00;
By = 1.00;
Cx = 0.00;
Cy = 1.00;
document.write(to_fixed(min_area_of_polygon(Ax, Ay, Bx, By, Cx, Cy), 2));
// This code is contributed by Saurabh Jaiswal
</script>