8
$\begingroup$

So I have a region defined by a MeshRegion,like

MeshRegion[{{0, 0}, {1, 1}, {2, 1/2}, {2, -1/2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 1}]}]

Which I would like to pick some random points on its border, like {0.5,0.5} and {1,-0.25}. Converting to Graphics and Rasterize, then picking random points is a way, but it would cause serious slowing down as most of the space is used to store the non-boundary points, not to mention the decreased accuracy. So is there a way to get the random points directly from the MeshRegion? The accuracy should be changeable.

$\endgroup$
1
  • 1
    $\begingroup$ why not RandomPoint[mr,10] where mr = MeshRegion[{{0, 0}, {1, 1}, {2, 1/2}, {2, -1/2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 1}]}] ? $\endgroup$
    – kglr
    Jun 3, 2018 at 9:21

1 Answer 1

9
$\begingroup$
mr = MeshRegion[{{0, 0}, {1, 1}, {2, 1/2}, {2, -1/2}}, {Line[{1, 2}], 
       Line[{2, 3}], Line[{3, 4}], Line[{4, 1}]}];
rp = RandomPoint[mr, 50];
Show[mr, Epilog -> {Red, PointSize[Large], Point @ rp}]

enter image description here

See the section RandomPoint >> Scope for examples of various forms the first argument of RandomPoint can take:

enter image description here

$\endgroup$

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.