This may be a minor point, but I'm wondering why RegionIntersection
of the two rectangles below gives 3 Lines rather than 2 Lines and 1 Point.
rect1 = {AbsoluteThickness[10], Red, r1 = Line[{{0, 2}, {2, 2}, {2, 0}, {0, 0}, {0, 2}}]};
rect2 = {AbsoluteThickness[2], Blue, r2 = Line[{{0, 1}, {3, 1}, {3, 0}, {0, 0}, {0, 1}}]};
Graphics[{rect1, rect2}, Frame -> True]
AbsoluteThickness
was used to show clearly where rect2 (blue) intersects with rect1 (red).
Now let's display, in purple, the intersection of regions r1, r2.
intersection = RegionIntersection[r1, r2]
Graphics[{rect1, rect2, Purple, AbsoluteThickness[10], intersection},
Frame -> True, AspectRatio -> 1/GoldenRatio]
Note that one of the lines, Line[{{2, 1}}]
, is really a point.
It plots it correctly, as a (very large) point.
But why didn't RegionIntersection
identify it as Point[{2, 1}]
?
Line[{{{2, 1}}, {{0, 0}, {0, 1}}, {{0, 0}, {2, 0}}}]
If line segments of the rectangles do not overlap, RegionIntersection
returns Points, as expected. (By the way, I had to add AbsolutePointSize
here because AbsoluteThickness
affects Lines but not Points. The "point" plotted above was actually a line of length 0.)
rect3 = {AbsoluteThickness[10], Green, r3 = Line[{{-4, 9}, {4, 9}, {4, 3}, {-4, 3}, {-4, 9}}]};
rect4 = {AbsoluteThickness[2], Gray, r4 = Line[{{2, 10}, {14, 10}, {14, 4}, {2, 4}, {2, 10}}]};
intersection = RegionIntersection[r3, r4]
Graphics[{rect3, rect4, Purple, AbsolutePointSize[8], intersection}, Frame -> True, AspectRatio -> 1/GoldenRatio]
Point[{{2, 9}, {4, 4}}]
RegionIntersection
does return aPoint
list. $\endgroup$RegionIntersection
in many other cases in which it returns a combination of Points and Lines $\endgroup$Line[{{{0, 1}}]
andLine[{{0, 1}}, {{0, 1}}}]
as the same thing. $\endgroup$