# Why does RegionWithin return False in this case?

Is there any mistake here? I expect it returns True but the result is False. I have been checking but couldn't find the mistake.

 myline = Line[{{-0.9999775897051473, 1.}, {-0.9971344923360166,
1.}, {-0.9837552105989325, 1.}, {-0.9703759288618484,
1.}, {-0.9436173653876803, 1.}, {-0.9168588019135122,
1.}, {-0.8117733541966873, 1.}, {-0.7066879064798623,
1.}, {-0.5106187050385604, 1.}, {-0.2980389526916474,
1.}, {-0.19879992351436487, 1.}, {-0.09956089433708235,
1.}, {-0.05091578283836483, 1.}, {-0.0022706713396473052,
1.}, {-0.00014244771157841357, 1.}}];
myregion =
Line[{{-5, 0}, {5, 0}, {5, 6}, {1, 1}, {0, 1}, {-5, 6}, {-5, 0}}];
RegionWithin[myregion, myline]


Here is the image showing the line and region.

We can use RegionUnion and RegionEqual to find if a line lies on another lines since if RegionUnion[A,B] and A are the same region, then B is the subset of A.

myregion =
Line[{{-5, 0}, {5, 0}, {5, 6}, {1, 1}, {0, 1}, {-5, 6}, {-5, 0}}];
line = Line[{.1 {5, 6} + .9 {1, 1}, .2 {5, 6} + .8 {1, 1}}];
Graphics[{{line}, {Red, Opacity[.2], AbsoluteThickness[8], myregion}}]
RegionEqual[RegionUnion[myregion, line], myregion]


Original

RegionWith[reg1,reg2]==True if and only if reg1 is contain reg2. Sine myregion only the boundary of the polygon which does not contain myline as we can see in the picture as below.

Graphics[{{myline}, {Opacity[.2], AbsoluteThickness[5], Red,
myregion}}]


So we need to construct a close region.

Graphics[{{Blue, myline}, {Red, Opacity[.2], AbsoluteThickness[5],
Polygon@myregion[[1]]}}]
RegionWithin[Polygon@myregion[[1]], myline]


True

Or

RegionWithin[BoundaryDiscretizeGraphics[Graphics[myregion]], myline]


True

Or

Clear[br];
br = BoundaryMeshRegion[myregion[[1]], Line@Range@Length@myregion[[1]]]
RegionWithin[br, myline]


True

• Could you explian a bit? And just an outside question, how would you check if a line is on a boundary of a region or not (a line is part of the regions' boundary)?
– hana
Commented Mar 27, 2022 at 23:35
• oops, somehow I miss the Polygon.
– hana
Commented Mar 27, 2022 at 23:55