3
$\begingroup$

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]

enter image description here

Here is the image showing the line and region.

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

Edit (Reply to comment)

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]

enter image description here

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

enter image description here

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

enter image description here

Or

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

True

Or

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

True

$\endgroup$
2
  • $\begingroup$ 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)? $\endgroup$
    – hana
    Mar 27, 2022 at 23:35
  • $\begingroup$ oops, somehow I miss the Polygon. $\endgroup$
    – hana
    Mar 27, 2022 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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