开发者

Algorithm for Max and Min diagonal of a convex polygon?

Is there a way better than a brute force comparison to get the max and min length diagonals of a polygon? To be more specific, I would like to find the ratio, so I can sort polygon on their "skinniness."

The polygons aren't too large (usually 4-8 faces per polygon), but there's a lot of them. I thought I'd just check with SO to see if there开发者_高级运维 was a better way of doing this.

Thanks in advance


The polygons aren't too large (usually 4-8 faces per polygon), but there's a lot of them.

I don't know if there's a faster solution than O(n^2), but for n <= 8 it's not gonna matter. If n = 8, you just have to check 20 diagonals (8 * 5 / 2). It's not so big multiplier itself, and any complex algorithm is likely to have a lot of computational overhead (data structures, sophisticated loops and checks).

One thing you can do to speed it up, though, is to throw away square root in the formula of distance between two points. First find min/max of (xi-xj)*(xi-xj) + (yi-yj)*(yi-yj), then apply square root. It's quite expensive operation and doing it 2 times instead of 20 could make a difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜