简体   繁体   English

阵列中两点之间的最大距离

[英]Biggest distance between two points in an array

Let's say I have an array with CGPoints (wrapped with NSValues ). 比方说,我有一个CGPoints阵列(包裹着NSValues)。 How can I get the two points which are most distant from each other. 如何获得彼此最远离的两个点。 I mean the distance between these two points is the biggest ? 我的意思是这两点之间距离最大 I can just check every two points but that does not look efficient. 我只能检查每两个点,但这看起来效率不高。 Is there a better way of doing this? 有更好的方法吗?

Thanks for help! 感谢帮助!

If there are not too many points (up to 1000, but if intensive, around 100), use the naive brute-force method O(n 2 ). 如果没有太多点(最多1000点,但如果密集,则大约100点),请使用幼稚的蛮力方法O(n 2 )。

I haven't read the details, but the biggest distance probably is computable in O(nlog n) with convex hull algorithm + rotating caliper . 我还没有阅读详细信息,但是最大距离可能是使用凸包算法 + 旋转卡尺在O(nlog n)中可计算的。

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

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