【计算几何初步:多边形中心】【HDU1115】Lifting the Stone
来源:互联网 发布:优考试软件下载 编辑:程序博客网 时间:2024/05/19 15:42
一.质点系重心公式
x=(x1*m1+x2*m2+x3*m3.....xn*mn)/M (M=m1+m2+m3+m4...+mn)
二.三角形重心
可直接求得,但在多边形剖分中 各三角形的质点的质量大小不一样 质量大小等于三角形面积.
三.多边形重心
三角形剖分+任意点的三角形剖分+三角形重心+质点系重心公式+任意点的三角形剖分
所以很容易知道一种很优美的计算公式(看代码)
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <ctime> #include <algorithm> #include <iostream>#include <sstream>#include <string>#define oo 0x13131313#define maxn 1000000+10using namespace std;struct point{double x,y;};point A[maxn];int N;double ansX,ansY;double Sarea;void input(){ansX=0;ansY=0;Sarea=0;cin>>N;for(int i=1;i<=N;i++){scanf("%lf%lf",&A[i].x,&A[i].y);}}void init(){freopen("a.in","r",stdin);freopen("a.out","W",stdout);}void get_Sarea(){for(int i=1;i<=N;i++){int j=i+1;if(j==N+1) j=1;Sarea+=(A[i].x*A[j].y-A[j].x*A[i].y)*0.5;}}void get_ansXansY(){for(int i=1;i<=N;i++){int j=i+1;if(j==N+1) j=1;double area=(A[i].x*A[j].y-A[j].x*A[i].y)*0.5;ansX+=area*(A[i].x+A[j].x); // area*(A[i].x+A[j].x+0)/3 质点的重量 ansY+=area*(A[i].y+A[j].y);}ansX=ansX/(3*Sarea); ansY=ansY/(3*Sarea);}int main(){int T;cin>>T;while(T--){input();get_Sarea();get_ansXansY();printf("%.2lf %.2lf\n",ansX,ansY);}return 0;}
0 0
- 【计算几何初步:多边形中心】【HDU1115】Lifting the Stone
- NYOJ3—多边形重心问题(计算几何)&&hdu1115 Lifting the Stone
- ACM-计算几何之Lifting the Stone——hdu1115
- hdu1115 Lifting the Stone (多边形重心)
- Lifting the Stone(hdu1115)多边形的重心
- hdu1115 Lifting the Stone 多边形重心
- HDU1115 Lifting the Stone
- HDU1115 Lifting the Stone
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
- hdu1115 Lifting the Stone(几何,求多边形重心模板题)
- HDOJ 1115 Lifting the Stone (计算几何+多边形重心)
- hdu1115 Lifting the Stone (求多边形重心)
- HDU1115 Lifting the Stone (求多边形的重心)
- HDU 1115 Lifting the Stone 计算几何
- HDOJ 1115 Lifting the Stone 【计算几何】
- hdu 1115 Lifting the Stone 计算几何
- HDU 1115 Lifting the Stone 计算几何(多边形找重心)
- hdu 1115 Lifting the Stone(计算几何(重心))
- android 打包签名时出现Conversion to Dalvik format failed
- make命令总结
- proftpd
- [C++]LeetCode: 32 Binary Tree Level Order Traversal II
- 1.js 基础笔记
- 【计算几何初步:多边形中心】【HDU1115】Lifting the Stone
- 第15章 实体和编码
- H3C交换机设置
- html版贪吃蛇
- 第十三周项目4-数组的排序(一)冒泡排序
- 设计一个窗体,该窗体显示一副图片,并使用ToolTip显示提示
- Struts2获取request,session,application几种方法
- 7种常用的面向对象设计原则
- nyoj水池数目