)
如果您喜欢此文章请收藏、点赞、评论谢谢祝您快乐每一天。已知正多边形n 3的三个顶点求由这三个顶点构成的正多边形四边相等的最小面积。例如输入0.00 0.001.00 1.000.00 1.00输出1.00通过取点 (1.00, 0.00) 形成边长为 1.0 的正方形因此面积 1.00。在继续之前需要注意一点边数必须至少为 4注意 n 3 的条件。这里我们需要找到正多边形的最小面积因此为了计算最小面积我们需要计算所需的 n 值。由于边长未知我们首先计算由这些点构成的三角形的外接圆半径。外接圆半径的计算公式为R abc / 4A 其中 a、b、c 是所构成三角形的三边长A 是三角形的面积。三角形的面积可以使用海伦公式计算。计算出三角形的外接圆半径后我们使用公式 A n × (sin(360/n) × r² /2)计算正多边形的面积。这里r 代表 n 边形n 边正多边形的外接圆半径。但是首先我们需要计算 n 的值。为了计算 n我们首先需要利用余弦公式 计算三角形的三个角cosA (b² c² - a² ) / 2bccosB (a² c² - b² ) / 2accosC (a² b² - c² ) / 2ab。然后n 的值由公式 n π / GCD(A, B, C)给出 其中 A、B 和 C 是三角形的三个角。计算出 n 后将其代入多边形面积的计算公式。以下是该方法的实现# Python3 program to find minimum area of# polygon of number of sides more than three# with given three points.# from math lib import every functionfrom math import *# assigning pi value to variablepi 3.14159265359# calculating gcd value of two double values .def gcd(x, y) :if abs(y) 1e-4 :return xelse :return gcd(y, fmod(x, y))# Calculating minimum area of polygon# through this function .def min_area_of_polygon(Ax, Ay, Bx,By, Cx, Cy) :# calculating the length of the sides of# the triangle formed from given points# a, b, c represents the length of different# sides of trianglea sqrt((Bx - Cx) * (Bx - Cx) (By - Cy) * (By - Cy))b sqrt((Ax - Cx) * (Ax - Cx) (Ay - Cy) * (Ay - Cy))c 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 herons formulaarea_triangle sqrt(semiperimeter *(semiperimeter - a) *(semiperimeter - b) *(semiperimeter - c))# thus circumradius of the triangle is derived# from the sides and area of the triangle calculatedRadius (a * b * c) / (4 * area_triangle)# Now each angle of the triangle is derived# from the sides of the triangleAngle_A acos((b * b c * c - a * a) / (2 * b * c))Angle_B acos((a * a c * c - b * b) / (2 * a * c))Angle_C acos((b * b a * a - c * c) / (2 * b * a))# Now n is calculated such that area is# minimum for the regular n-gonn pi / gcd(gcd(Angle_A, Angle_B), Angle_C)# calculating area of regular n-gon through# the circumradius of the trianglearea (n * Radius * Radius *sin((2 * pi) / n)) / 2return area# Driver Codeif __name__ __main__ :# three points are given as input .Ax 0.00Ay 0.00Bx 1.00By 1.00Cx 0.00Cy 1.00print(round(min_area_of_polygon(Ax, Ay, Bx,By, Cx, Cy), 1))# This code is contributed by Ryuga输出1.00时间复杂度 O(log(min(A,B,C)))辅助空间 O(1)因为没有占用额外的空间。如果您喜欢此文章请收藏、点赞、评论谢谢祝您快乐每一天。