10
$\begingroup$

This may be a minor point, but I'm wondering why RegionIntersectionof 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).

pic1


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}}}]

pic3


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}}]

pic4

$\endgroup$
  • $\begingroup$ interesting, notice if the intersection is only discrete points then RegionIntersection does return a Point list. $\endgroup$ – george2079 Mar 28 '16 at 18:04
  • $\begingroup$ Yes, I've used RegionIntersection in many other cases in which it returns a combination of Points and Lines $\endgroup$ – DavidC Mar 28 '16 at 18:16
  • $\begingroup$ Looks like a bug to me, you may want to send this to support@wolfram.com $\endgroup$ – user21 Mar 29 '16 at 1:32
  • 1
    $\begingroup$ I can't see this as a bug. The result is correct, both mathematically (a zero-length line is a point) and graphically (it displays as a point). For as long I can remember, Mathematica has always treated Line[{{{0, 1}}] and Line[{{0, 1}}, {{0, 1}}}] as the same thing. $\endgroup$ – m_goldberg Mar 29 '16 at 2:00
  • 1
    $\begingroup$ Technically, I suppose, a line with no length may be equivalent to a point. However, I would expect Mathematica to return it in its standard form. In the particular case I am working on, I am trying to count the number of times a line crosses another line. Of course there is a workaround, but it is a bit clumsy. $\endgroup$ – DavidC Mar 29 '16 at 2:54
3
$\begingroup$

Querying the documentation I believe the answer to this question is because of this property of the function called RegionEmbeddingDimension:

enter image description here

enter image description here

In the first case:

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}}]};
intersection1=RegionIntersection[r1,r2]
Graphics[{rect1,rect2,Purple,AbsoluteThickness[10],intersection1},
Frame->True,AspectRatio->1/GoldenRatio]

enter image description here

Head[intersection1]

Line

It is the embedding dimension that gives the dimension of space. As the line was the largest dimension, it prevailed

In the second case:

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}}]};
intersection2=RegionIntersection[r3,r4]
Graphics[{rect3,rect4,Purple,AbsolutePointSize[8],intersection2},
Frame->True,AspectRatio->1/GoldenRatio]

enter image description here

Head[intersection2]

Point

It is the embedding dimension that gives the dimension of space. As the point was the only dimension, it prevailed

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.