开发者

Get non-over lapping area of two rectangles

How can I get the "Polygon" or "Region" of the non-over lapping area of two rectangles.

Like (A-B), w开发者_如何学Gohere "A" and "B" are rectangles. We can easily get the intersecting rectangle using the Rectangle.Intersect method but I want the part of a rectangle that is not common.

Thanks


Rectangle a, b;

var region = new Region(a);
region.Exclude(b);

Region.Exclude(Rectangle rect) method


You can get the intersection of two rectangles using Intersect. That means that you can get the area of the intersection. So, take the area of the intersection multiplied by two (multiplied by two because it occupies the same area over both rectangles) and subtract it from the sum of the total area of the two rectangles.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜