Find centerpoint of polygon in JavaScript(在 JavaScript 中查找多边形的中心点)
问题描述
我有一个来自谷歌地图的地点"对象,它有一组坐标,代表给定位置的边界框,比如伦敦.每组坐标都有一个纬度和经度.
I have a "place" object from Google Maps which has a set of coordinates that represent a bounding box for a given location, say London. Each set of coordinates has a latitude and longitude.
我已经编写了以下代码来查找中心点,但我不确定它是否确实产生了中心点.如果多边形有 5 个点而不是 4 个呢?另外,这是否可以以更有效的方式完成,操作更少?
I have written the below code to find the centerpoint, but I am not sure if it does actually produce the centerpoint. What if the polygon has 5 points instead of 4? Also, can this be done in a more efficient way, with less operations?
示例.
推荐答案
这应该得到 centroid 任何 区域wiki/多边形" rel="noreferrer">多边形
This should get the centroid of the area of any polygon
关于 jsfiddle
这篇关于在 JavaScript 中查找多边形的中心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!