5
$\begingroup$

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?

$\endgroup$
1

1 Answer 1

12
$\begingroup$

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

Mathematica graphics

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.