3
$\begingroup$

I would like to probabiistically estimate the convexity coefficient of a MeshRegion, described as -

Given a region $\mathscr{K}$, calculate the probability that a line with randomly chosen endpoints $\{p_1,p_2\}\in\mathscr{K}$, will be wholly contained within $\mathscr{K}$.

(NB - I know how to do this the 'hard way' e.g. directly using the polygon edges / lines, but I'm hoping to take advantage of Mathematica's new-but-not-great geometric computation additions.)

So- here's a $\mathbb{R}^2$ sort-of-not-really convex region (I eventually need $\mathbb{R}^3$ but this makes the demo simpler)

rK = MeshRegion[{{0, 0}, {1, 0}, {0.1, 0.5}, {1, 1}, {0, 1}, {Polygon[{1, 2, 3, 4, 5}]}]

Mathematica graphics

Now, let's generate some random lines with endpoints in rK -

SeedRandom[02134];
lines = Table[Line[{RandomPoint[rK], RandomPoint[rK]]}], {20}];
Show[{rK, Graphics[lines]}]

Mathematica graphics

Of the 20 lines, 14 are fully inside rK, so the convexity coef is (roughly, of course) 14/20. Based on the tools available for geometric computation in 10.x I can't seem to find a way to test if a line (or other Region of some kind) is contained within another region. Points are, of course, pretty trivial (e.g. RegionMember)

Element[{0.1, 0.1}, rK]

yields True, and the endpoints of the first line in our random list

Show[{rK, Graphics[lines[[1]]]}]

Mathematica graphics

RegionMember[rK, lines[[1, 1]]]

are both True but obviously the line itself isn't contained within the region.

Unfortunately, you can't do anything as clever as, say,

Element[MeshRegion[lines[[1, 1]], Line[{1, 2}]], rK]

Mathematica graphics

But it might be nice to... I've had extremely mixed success with the various computational geometry routines, especially with complicated / 3D MeshRegions that are my day-to-day currency. Does anyone have any insight here that might help?

$\endgroup$
  • $\begingroup$ Related: How to check if a line segment intersects with a polygon? Just replacing RegionIntersection with RegionDifference in some of those answers should work. $\endgroup$ – Rahul Jan 3 '16 at 21:06
  • $\begingroup$ I have tried various assortments of Boolean stuffs with this but can't seem to hit on the right thing. Most of the time, everything comes out 'unsimplified' like the Element example. Hmm- I will probe further! $\endgroup$ – flip Jan 3 '16 at 21:19
  • $\begingroup$ NB to whosoever 'oversees' the syntax highlighting for this SX, RandomPoint is a real MMa symbol. $\endgroup$ – flip Jan 3 '16 at 21:29
  • 2
    $\begingroup$ Ah, it doesn't seem to like MeshRegions. If you keep them as graphics primitives it works: RegionDimension[RegionDifference[lines[[1]], Polygon[{{0, 0}, {1, 0}, {0.1, 0.5}, {1, 1}, {0, 1}}]]] gives 1, showing that the line is not entirely contained in the polygon. $\endgroup$ – Rahul Jan 3 '16 at 21:40
  • $\begingroup$ Well isn't that fascinating?! Thanks! Now to do a little checking if I can get it to happen in R^3... magic! $\endgroup$ – flip Jan 3 '16 at 23:20

Your Answer

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

Browse other questions tagged or ask your own question.