2
$\begingroup$

Why does the first one return EmptyRegion[2] while the second one works? I expected the result is Line[{{0, 0}, {1, 1}}] as the second one.

RegionIntersection[
 Polygon[{{-1, 1}, {1, 1}, {1, 0}, {-1, 0}, {-1, 1}}], 
 Line[{{0, 0}, {1, 1}}]]

enter image description here

RegionIntersection[Polygon[{{-1, 1}, {1, 1}, {1, 0}, {-1, 0}}], 
 Line[{{0, 0}, {1, 1}}]]

enter image description here

Aslo how does EmptyRegion is defined? I read the docs but still not quite clear. It seems like a point is not empty in R but empty in R2.

How would I define a polygon region like above but without the boundary?

$\endgroup$
8
  • $\begingroup$ On V12 I got the output Line[{{0, 0}, {1, 1}}] from the first one; see image $\endgroup$
    – bmf
    Apr 5 at 6:25
  • $\begingroup$ @bmf that is strange. Mine is "12.2.0 for Microsoft Windows (64-bit) (December 12, 2020)" $\endgroup$
    – hana
    Apr 5 at 6:33
  • $\begingroup$ thanks for letting me know. Mine is 12.0.0. Maybe others can check on other versions. If nobody checks, I will run a check on 13.0.0 in the morning $\endgroup$
    – bmf
    Apr 5 at 6:40
  • $\begingroup$ got the same output as OP (EmptyRegion[2] and Line[{{0, 0}, {1, 1}}]]) on v13.0.0.0 $\endgroup$
    – thorimur
    Apr 5 at 6:48
  • 2
    $\begingroup$ RegionEqual[Polygon[{{-1, 1}, {1, 1}, {1, 0}, {-1, 0}}], Polygon[{{-1, 1}, {1, 1}, {1, 0}, {-1, 0}, {-1, 1}}]] is True indicate that it is a bug. $\endgroup$
    – cvgmt
    Apr 5 at 9:41

1 Answer 1

2
$\begingroup$
ln1 = Line[{{0, 0}, {1, 1}}];
pts0 = {{-1, 1}, {1, 1}, {1, 0}, {-1, 0}, {-1, 1}}
p0 = Polygon@pts0
p1 = Polygon[{{-1, 1}, {1, 1}, {1, 0}, {-1, 0}}]
p2 = CanonicalizePolygon[p0]

These are regions nevertheless:

RegionQ /@ {p0, p1, p2}

{True, True, True}

but a proper polygon produces the desired results for RegionIntersection. The polygon p1 you defined just happened to be a correct polygon with no repeating points.

RegionIntersection[#, ln1] & /@ {p0, p1, p2}

{EmptyRegion[2], Line[{{0, 0}, {1, 1}}], Line[{{0, 0}, {1, 1}}]}

$\endgroup$
2
  • $\begingroup$ Thanks, actually the first one had problem so I removed the repeating points. I thought the first one should work as well. $\endgroup$
    – hana
    Apr 5 at 7:24
  • $\begingroup$ Frankly your question has not been answered. What I have is a workaround only. If something is recognized as a Region as I showed above, then it must play nice with other regions. $\endgroup$
    – Syed
    Apr 5 at 11:09

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.