I am a newbie to Mathematica. I have some 2D point data, and I generated a ConvexHullMesh from it. Now, I want to generate a certain number of random points within the convex hull. What is the best way to do it?
$\begingroup$ $\endgroup$
1 - $\begingroup$ Have you seen How to generate random points in a region? $\endgroup$MarcoB– MarcoB2016-12-12 05:58:48 +00:00Commented Dec 12, 2016 at 5:58
Add a comment |
1 Answer
$\begingroup$ $\endgroup$
A convex hull returned by ConvexHullMesh can be used directly as a region specification in RandomPoint.
Below I generate a few random 2D points to use to generate a convex hull, then use that hull as a region to generate five new points with RandomPoint. The original points are shown in Black; the new random ones in red.
originalPoints = RandomReal[{-10, 10}, {7, 2}]; hull = ConvexHullMesh@originalPoints; newpts = RandomPoint[hull, 5]; Show[ hull, Graphics[{ PointSize[0.01], Point@originalPoints, Red, PointSize[0.02], Point@newpts }] ] 