明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 16366|回复: 5

已知任意多边形顶点坐标,求多边形形心坐标

[复制链接]
发表于 2012-2-1 16:24 | 显示全部楼层 |阅读模式
已知任意多边形(包括L、T、I等)的顶点坐标,并且已按顺时针或逆时针排序。哪位大师知道怎么求这个多边形的形心坐标呀
 楼主| 发表于 2012-2-1 16:26 | 显示全部楼层
不好意思,补充一点,不能用作面域的方法来提取形心坐标
发表于 2012-2-1 17:59 | 显示全部楼层
你的意思是不是在没画图的情况下直接算出其形心坐标?可能有点困难,期待高手解决。
发表于 2012-2-1 18:02 | 显示全部楼层
本帖最后由 qjchen 于 2012-2-1 18:05 编辑

http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon

其中的这个就是公式

Centroid of polygon
The centroid of a non-self-intersecting closed polygon defined by n vertices (x0,y0), (x1,y1), ..., (xn−1,yn−1) is the point (Cx, Cy), where   [对于一个封闭的非自交的多边形,形心公式如下]



and where A is the polygon's signed area,





In these formulas, the vertices are assumed to be numbered in order of their occurrence along the polygon's perimeter, and the vertex ( xn , yn ) is assumed to be the same as ( x0 , y0 ). Note that if the points are numbered in clockwise order the area A, computed as above, will have a negative sign; but the centroid coordinates will be correct even in this case [注意,有可能计算出来的面积会是负数,但是形心的位置是不会错的]


假如需要代码的话,可以参考这里 http://stackoverflow.com/questions/2792443/finding-the-centroid-of-a-polygon

gile和Evgeniy也曾经写过带弧线的多线的Lisp代码,不过方法要更加复杂了

假如还需要二次矩的计算的话,可以参考这里
http://paulbourke.net/geometry/polyarea/上面这个网站还有大量的几何图形知识,在http://paulbourke.net/geometry/

 楼主| 发表于 2012-2-1 19:59 | 显示全部楼层
谢谢大师!俺就按这个来编码。
发表于 2014-1-27 11:56 | 显示全部楼层
本帖最后由 mkhsj928 于 2014-1-27 12:00 编辑
qjchen 发表于 2012-2-1 18:02
http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon

其中的这个就是公式

注意首尾点必须相同,这样才代表闭合“and the vertex ( xn , yn ) is assumed to be the same as ( x0 , y0 )"

刚开始老是不对,才发觉是未闭合的原因!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-2 15:32 , Processed in 1.260312 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表