开发者

How to find ALL points that lie on the outline of a polygon's convex hull (Matlab)

开发者 https://www.devze.com 2023-02-22 16:18 出处:网络
sorry if this question might seem simple but I couldn\'t figure it out. Imagine two arbitrary Rectangles that are randomly overlaped so that their outlines intersect at only two locations. Now you cu

sorry if this question might seem simple but I couldn't figure it out.

Imagine two arbitrary Rectangles that are randomly overlaped so that their outlines intersect at only two locations. Now you cut the area of overlap out of Rectangle 1.

This "bitten Rectangle 1" has now the following points (vertices): (1) All points of Rectangle 1 that lie outside of Rectangle 2, (2) All points of Rectangle 2 that lie inside Rectangle 1 and (3) the two intersection points.

The problem know is the following: How can I get the order of the new points so 开发者_运维问答that the functions plot(...) or fill(...) would draw the right "Bitten Rectangle 1"?

What I did so far: I determined the convex hull of all the points that lie outside of Rectangle 2 + the intersection points. Then one has to add the new points that lie inside rectangle 1 (due to overlap with Rectangle 2) between the indices of the first and second intersection point also in the right order.

The problem with this convex hull approach is that it only works if the intersection points lie on different lines of Rectangle 1, because then they are part of the convex hull. If they lie on the same line they are no longer treated as part of the convex hull.

What I'd need is a method to get the order of all possible points that lie on the convex hull and not only the outer most ones.

Hope anybody can help me... Thank you in advance, Patrick


In Matlab, there is an amazing function called polybool that let you do any set operation on polygons: http://www.mathworks.com/help/toolbox/map/ref/polybool.html

All you have to do is to define four arrays describing the rectangles (rect1x, rect1y, rect2x and rect2y) and to call [resultx resulty] = polybool('subtraction', rect1x, rect1y, rect2x, rect2y). The resulting arrays will be describing the "Bitten Rectangle 1".

0

精彩评论

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

关注公众号