简体   繁体   English

Java:凸多边形的周长

[英]Java: Perimeter of a convex polygon

I have an ArrayList of some Point -s. 我有一些Point -s的ArrayList It's guaranteed that the Points are part of a convex polygon. 确保这些点是凸多边形的一部分。

How can I calculate the perimeter of this convex polygon? 如何计算该凸多边形的周长?

Update: The Points in the ArrayList are out of any order 更新:ArrayList中的点没有任何顺序

Update 2: All the points are part of the convex polygon's edge 更新2:所有点都是凸多边形的边的一部分

Are the points in order? 要点了吗? If so, you just need to sum up the distance from each vertex to the next 如果是这样,您只需要总结每个顶点到下一个顶点的距离

If the points are not ordered, its impossible without determining the correct order. 如果未对点进行排序,则无法确定正确的顺序。 Thats because if there are more than 3 points there is more than one polygon they could form. 那是因为如果存在3个以上的点,则可以形成一个以上的多边形。

I'm not entirely sure the constraint that the points are forming a convex polygon is sufficient to determine a canonic shape from the point cloud. 我不完全确定这些点形成凸多边形的约束足以从该点云确定规范形状。

My guess is that by taking a random point from the list, and then looking for the nearest remaining point you can build a canonic order. 我的猜测是,通过从列表中获取一个随机点,然后寻找最接近的剩余点,您可以建立一个规范顺序。 From there its just summing up the length of the lines formed by consecutive points. 从那里开始,它只是对由连续点形成的线的长度求和。

Edit: On second thought, scratch that idea. 编辑:第二个想法,抓紧那个想法。 It won't work for all cases. 并非在所有情况下都有效。 That leaves you with permuting the points and checking if the formed polygon is indeed convex. 这样就可以对点进行置换并检查所形成的多边形是否确实是凸的。

The question on how to check if a polygon is convex has been asked and answered here: How do determine if a polygon is complex/convex/nonconvex? 此处已询问并回答有关如何检查多边形是否为凸形的问题: 如何确定多边形是否为复形/凸形/非凸形?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM