# The region and polygon don't match. Is it a bug?

Bug introduced in 12.3, and persisting through 13.2.1 or later.

Is this a bug? The region and polygon don't match. How can I fix this?
I would prefer to continue using "Implicit", as it is related to one of my previous threads here.

polygon = Polygon@{{0, 1}, {1, 1}, {5, 5}, {5, 0}, {0, 0}};
region = RegionConvert[polygon, "Implicit"];
{Graphics@polygon,  Region@region}


"13.0.1 for Microsoft Windows (64-bit) (January 28, 2022)"

EDIT:

I don't think it's related to plot quality, as this result of the code indicates that the intersection between the polygon and the line is a line, but that is incorrect.
If the region were represented correctly, the result of this RegionIntersection[region, ImplicitRegion[y == 3 - 2 x && x <= 1, {x, y}]] should be a point or RegionDimension of 0.
Hope that I'm wrong and it's not a bug so we can solve this problem.

polygon = Polygon@{{0, 1}, {1, 1}, {5, 5}, {5, 0}, {0, 0}};
region = RegionConvert[polygon,      "Implicit"];
RegionDimension@  RegionIntersection[region,    ImplicitRegion[y == 3 - 2 x && x <= 1, {x, y}]]


• may be it is a bug. But "Mesh" does not have this issue. Screen shot !Mathematica graphics Mar 2 at 14:18
• The RegionDimension issue appeared in v12.3. In v12.2 this worked correctly if one substituted RegionConvert with equivalent function or copied the result from a newer version. Mar 4 at 6:51

The situation is the same even in 13.2.0.

One way to fix this if we want to keep "Implicit" is the following:

polygon = Polygon@{{0, 1}, {1, 1}, {5, 5}, {5, 0}, {0, 0}};
region = RegionConvert[polygon, "Implicit"];
{Graphics@polygon, Region@CanonicalizePolygon[region]}


• +1 I am using a region for this purpose , but now I am concerned that using Mesh together with DiscretizeRegion might reduce the accuracy of my calculations.
– hana
Mar 2 at 14:47
• It does not seem to work with every polygon. This gives me an error. Region@CanonicalizePolygon@ RegionConvert[ Polygon@{{0, 1}, {1, 1}, {5, 5}, {5, 0}, {-5, 0}, {-5, 5}}, "Implicit"]
– hana
Mar 2 at 14:57
• @hana After some tests, I think it has to do with this point {-5, 5}. Not sure why it does not like it. But I agree it's weird. I have not found a work-around for this example while keeping "Implicit"
– bmf
Mar 3 at 1:04
• @bmf The problem can be simplified down to RegionDimension[ImplicitRegion[x >= 0 && x == y && x + y <= 0, {x, y}]] returning 1 although the region consists of a single point at the origin. I'll update the bug report I've submitted to WRI on the subject. Mar 4 at 6:22
• ... and even this is wrong: RegionDimension[ImplicitRegion[x >= 0 && x <= 0 && y == 0, {x, y}]] (1). Also, the problem seems to be a regression in v12.3. Mar 4 at 6:34

# It's both numerical and display issue, and also Analytically a bug.

I think this is a problem in all areas: numerical analytical and a display issue.

## Numerical

When evaluating the region numerically coordinates outside but very close ($$64\times$$ $MachineEpsilon) to the edge are interpreted incorrectly as inside the region. TableForm@Table[ {k ϵ, RegionMember[region, {1,1}+{0,1}$MachineEpsilon*k]}
,{k, 60, 70,1}
]


## Graphical

The Region plot is very bad quality by default, but if you focus on the area of interest one can see that it's interpreted correctly.

Region[
region
, PlotRange ->#
, Axes->True
]& /@ {
{ {-10, 10}, {-10, 10} },
All,
{ {0.8, 1.2}, {0.8, 1.2} }
}


## Analytical

No problems here

RegionMember[region, {1,1}+{0,1}/10^100]
(* False *)

RegionMeasure@  RegionIntersection[region, ImplicitRegion[y == 2 -  x && x<1, {x, y}]]
(* 0 *)


but this is a problem too

RegionMeasure@  RegionIntersection[region, ImplicitRegion[y == 2 -  x && x<=1, {x, y}]]


I would call this a bug, you should contact Wolfram Support.

• What would you think about the past that I just updated in the question?
– hana
Mar 2 at 16:44
• @hana I agree, this is a bug. Mar 2 at 16:56
• Do you know any possible workarounds and keep "Implicit"?
– hana
Mar 2 at 17:31
• @hana I think my answer provides a workaround. I submitted this as a bug report to WRI. If your license account is a particularly well-paying customer you may want to submit it again just to catch their attention. Some bugs are fixed surprisingly quickly, but some submissions by mere mortals may be piled up for decades... Mar 3 at 9:27

The change in polygon shape is a discretisation problem but doesn't affect the RegionDimension part. That appears to be a bug, very similar to one which I have reported to WRI earlier, although not necessarily the same.

In this case you can work around this by Reduce'ing the implicit equation resulting from the intersection:

RegionIntersection[region,
ImplicitRegion[y == 3 - 2 x && x <= 1, {x, y}]] /.
ImplicitRegion[pred_, vars_] :>
ImplicitRegion[Reduce[pred, vars, Reals], vars] // RegionDimension

(* 0 *)

• Thank you, I will check it out today. I attempted to write an ImplicitRegion myself by dividing a region into many smaller ones and combining them. While the combined region works, the entire code does not seem to be functioning properly. Unfortunately, I believe I may have deleted that code.
– hana
Mar 3 at 17:14
• Could you please explain why using Reduce makes it work in this case?
– hana
Mar 6 at 11:33
• @hana Reduce is able to simplify the region to simply a form corresponding to ImplicitRegion[x == 1 && y == 1, {x, y}], which RegionDimension recognises as a single point. It's more of a question why v12.3 stopped handling the original form correctly... Mar 6 at 12:46

RegionPlot generally produces higher quality than Region and has the options PlotPoints and MaxRecursion to help resolve any issues.

Clear["Global*"]

polygon = Polygon@{{0, 1}, {1, 1}, {5, 5}, {5, 0}, {0, 0}};

region = RegionConvert[polygon,
"Implicit"] /. {\[FormalX] -> x, \[FormalY] -> y}

(* ImplicitRegion[(x + 4 y >= 5 && x <= 5 && y <= x) || (x >= 0 && y >= 0 &&
x + 4 y <= 5 && y <= 1), {x, y}] *)

{Graphics@polygon, Region@region,
RegionPlot[region[[1]], {x, 0, 5}, {y, 0, 5},
Frame -> False, BoundaryStyle -> None]}


• I don't think it's related to plot quality, as this result of the code indicates that the intersection between the polygon and the line is a line, but that is incorrect. polygon = Polygon@{{0, 1}, {1, 1}, {5, 5}, {5, 0}, {0, 0}}; region = RegionConvert[polygon, "Implicit"] /. {\[FormalX] -> x, \[FormalY] -> y}; RegionDimension@ RegionIntersection[region, ImplicitRegion[y == 3 - 2 x && x <= 1, {x, y}]]
– hana
Mar 2 at 16:04
• It the region were represented correctly, the result of this RegionIntersection[region, ImplicitRegion[y == 3 - 2 x && x <= 1, {x, y}]] should be a point or RegionDimension of 0.
– hana
Mar 2 at 16:13
• Then I recommend that you edit your question to reflect the issue that you have. As presented, it appears to be a graphical issue. Note that the RegionDimension result doesn't necessarily mean that the region is wrong, it could be that the RegionIntersection is wrong. Further inspection is required. Mar 2 at 16:22

I am sure this is not a bug. In many cases the Region command without options produces a plot of low quality. The following works well in 13.2 on Windows 10.

Region[region, PlotRange -> {{-1, 5}, {-1, 5}}]


• I believe that the issue is not related to the quality of the plot, as it produced an incorrect result when I used region intersection.
– hana
Mar 2 at 14:49
• @hana: Sorry, don't understand. I don't see any intersection in region. Can you elaborate your comment , giving us a code inastead of empty words? TIA. Mar 2 at 14:59
• Sorry, what I meant to say is that I checked the RegionDimension>=1 intersection of the region with the line y=ConditionalExpression[3 - 2 x, x <= 1], and the result should be False. However, it is incorrectly showing True because the wrong part of the region has been included.
– hana
Mar 2 at 15:05
• @hana: You are not right. The command region = RegionConvert[polygon, "Implicit"] performs ImplicitRegion[(-\[FormalX] - 4 \[FormalY] <= -5 && 5 \[FormalX] <= 25 && -4 \[FormalX] + 4 \[FormalY] <= 0) || (-\[FormalX] <= 0 && -5 \[FormalY] <= 0 && \[FormalX] + 4 \[FormalY] <= 5 && \[FormalY] <= 1), {\[FormalX], \[FormalY]}] and we see that region incudes its boundary . In any case the plots of open and closed polygons do not take into account the boundaries of these. Mar 2 at 15:37
• @user64494 RegionDimension` returning 0 means that the dimension consists of zero-dimensional disconnected subregions, in practice points, not that it is empty. In this case the intersection is a single point. If region is empty the region dimension is minus infinity. Mar 3 at 9:12