多边形重心的计算 |
您所在的位置:网站首页 › 梯形重心到角点的距离 › 多边形重心的计算 |
例题: 传送门:HDU 1115 方法一: 累加求和重心。 设平面上有n个点(xi,yi)(i=1、2、3……n),其多边形重心G(x,y)为: 方法二: 这里有几个定理需要用到: 定理一:已知三角形△A1A2A3的顶点坐标Ai ( xi, yi ) ( i =1, 2, 3) 。它的重心坐标为: xc = (x1+x2+x3) / 3 ; yc = (y1+y2+y3) / 3 ; 定理二:已知三角形△A1A2A3的顶点坐标Ai ( xi , yi ) ( i =1, 2, 3) 。该三角形的面积为: S = ( (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) ) / 2 ; △A1A2A3 边界构成逆时针回路时取+ , 顺时针时取 -。 另外在求解的过程中,不需要考虑点的输入顺序是顺时针还是逆时针,相除后就抵消了。 方法: (1).以多边形的一个顶点O为原点(可以选输入的第一个点作为原点),作连接O与其他所有非相邻顶点的线段,将多边形(n条边)分为n-2个三角形。 (2).求每个三角形的面积和重心 设其中一个三角形的重心为G(cx,cy),顶点坐标分别为A1(x1,y1),A2(x2,y2), A3(x3,y3),则有cx = (x1+x2+x3) / 3 ; cy = (y1+y2+y3) / 3 ; 面积为S = ( (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) ) / 2 ; (3).求多边形的重心 公式:cx = (∑ cx[i]*s[i]) / ∑s[i] ; cy = (∑ cy[i]*s[i] ) / ∑s[i];其中(cx[i], cy[i]), s[i]分别是所划分的第i个三角形的重心坐标和面积。另外,在(2)中求每个重心坐标时要除以3,实际上不需要在求每个三角形坐标时都除以3,只需要求出∑ cx[i]*s[i]后一次性除以3即可。
HDU 1115 Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem Description There are many secret openings in the floor which are covered by a big heavy stone. When the stone is lifted up, a special mechanism detects this and activates poisoned arrows that are shot near the opening. The only possibility is to lift the stone very slowly and carefully. The ACM team must connect a rope to the stone and then lift it using a pulley. Moreover, the stone must be lifted all at once; no side can rise before another. So it is very important to find the centre of gravity and connect the rope exactly to that point. The stone has a polygonal shape and its height is the same throughout the whole polygonal area. Your task is to find the centre of gravity for the given polygon. Input The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer N (3 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |