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.
精彩评论