注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

没有你的天堂

Cobra'Nails' Blog.

 
 
 

日志

 
 

How to determine if a list of polygon points are in clockwise order?  

2010-12-30 15:45:00|  分类: 光明石碑 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

如何判断一组点是否是顺时针顺序?

stackoverflow上找到一个办法:

http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order

Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here's a simple one that will work with non-convex polygons (it'll even work with a self-intersecting polygon like a figure-eight, telling you whether it's mostly clockwise).

Sum over the edges, (x2-x1)(y2+y1). If the result is positive the curve is clockwise, if it's negative the curve is counter-clockwise. (The result is twice the enclosed area, with a +/- convention.)

point[0] = (5,0) edge[0]: (6-5)(4+0) = 4point[1] = (6,4) edge[1]: (4-6)(5+4) = -18point[2] = (4,5) edge[2]: (1-4)(5+5) = -30point[3] = (1,5) edge[3]: (1-1)(0+5) = 0point[4] = (1,0) edge[4]: (5-1)(0+0) = 0 --- -44 counter-clockwise

  评论这张
 
阅读(3)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018