作者yoco315 (眠月)
站内Programming
标题Re: [问题] 不规则区域的重心
时间Fri Oct 9 22:56:59 2009
※ 引述《makiyolove (暴力熊)》之铭言:
: 各位版友好:
: 在一起)。现在我想要在这个不规则图形上找重心,但是找
google 了一下看到这个..
http://www.exaflop.org/docs/cgafaq/cga2.html
我还看完了,顺便帮你整理出重点:
一整个多边形的重心好似很难算,
但是一个三角形的重心很好算,
两个三角形的重心也很好算,三个三角型的重心也很好算,
四个也很好算…五个也…六个也…七个也…八格也路…
原来如此!我们只要把多边形三角化以後,
求所有三角形的重心的重心就好了!
报告完毕。
我人真好 QQ
--
Subject 2.02: How can the centroid of a polygon be computed?
The centroid (a.k.a. the center of mass, or center of gravity) of a polygon
can be computed as the weighted sum of the centroids of a partition of the
polygon into triangles. The centroid of a triangle is simply the average of
its three vertices, i.e., it has coordinates (x1 + x2 + x3)/3 and (y1 + y2 +
y3)/3. This suggests first triangulating the polygon, then forming a sum of
the centroids of each triangle, weighted by the area of each triangle, the
whole sum normalized by the total polygon area. This indeed works, but there
is a simpler method: the triangulation need not be a partition, but rather
can use positively and negatively oriented triangles (with positive and
negative areas), as is used when computing the area of a polygon. This leads
to a very simple algorithm for computing the centroid, based on a sum of
triangle centroids weighted with their signed area. The triangles can be
taken to be those formed by one fixed vertex v0 of the polygon, and the two
endpoints of consecutive edges of the polygon: (v1,v2), (v2,v3), etc. The
area of a triangle with vertices a, b, c is half of this expression:
(b[X] - a[X]) * (c[Y] - a[Y]) -
(c[X] - a[X]) * (b[Y] - a[Y]);
Code available at ftp://grendel.csc.smith.edu/pub/code/centroid.c (3K).
Reference: [Gems IV] pp.3-6; also includes code.
--
To iterate is human, to recurse, divine.
递回只应天上有, 凡人该当用回圈. L. Peter Deutsch
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.160.107.24
1F:推 tropical72:我没试过,不过有人说误差蛮大的123.195.164.115 10/10 01:27
2F:推 Fenikso:这方法是准的哪会有误差... 220.133.186.66 10/10 03:25
3F:推 LPH66:数值(浮点数)误差吧... 140.112.28.92 10/10 05:54
4F:推 Fenikso:可是整个演算法就一次整数除法 220.133.186.66 10/10 09:18
5F:→ Fenikso:其他都是整数的加减乘.. 220.133.186.66 10/10 09:18
6F:→ Fenikso:如果允许有理数运算的话完全是准的 220.133.186.66 10/10 09:19
7F:→ Fenikso:就算用double也不会差多少 220.133.186.66 10/10 09:19
8F:→ yoco315:我有问题(举手) 关於误差大的说明 118.160.107.24 10/10 23:32
9F:→ yoco315:有没有更详细的资料?或是推荐较准的方法? 118.160.107.24 10/10 23:32
10F:推 AmosYang:八格也路 XD 65.87.177.87 10/11 10:21
11F:推 denny61001:大家都好强喔>///< 我什麽都看不懂 124.218.7.236 10/11 19:11
12F:推 LouisXIV:我是不知道应该要多准才行,不过既然是 220.133.41.64 10/12 01:45
13F:→ LouisXIV:影像处理的话,其实把pixel坐标平均一 220.133.41.64 10/12 01:46
14F:→ LouisXIV:下就可以得到答案了!误差应该在一个 220.133.41.64 10/12 01:46
15F:→ LouisXIV:pixel以内,感觉上已经可以接受了! 220.133.41.64 10/12 01:46