5

Suppose you have a list of data points, either in 2D or 3D; is it possible to plot the minimal bounding region containing all the points?

Ignoring holes etc.

MarcoB
  • 67,153
  • 18
  • 91
  • 189
MKF
  • 591
  • 2
  • 10

2 Answers2

8

Given a set of random 3D points, you can create a mesh that represents the minimum bounding region using BoundingRegion[] or ConvexHullMesh[] as MarcoB suggested. ConvexHullMesh[] is probably the simplest, though BoundingRegion[] has some nice options for other sorts of regions like the smallest sphere or cuboid.

BlockRandom[SeedRandom[1234]; pts = RandomReal[{-1, 1}, {50, 3}];]
cvx = ConvexHullMesh[pts]
br = BoundingRegion[pts, "MinConvexPolyhedron"]

This should give you two meshes that look identical to this:

Convex hull mesh of random 3d points.

You can choose whichever function you prefer. It's also possible to show the points themselves along with the mesh:

Show[HighlightMesh[br, Style[2, Opacity[0.5]]], Graphics3D[Point[pts]]]

Convex hull mesh of random 3d points with points shown.

MassDefect
  • 10,081
  • 20
  • 30
6

For the 2D case, you can use the shape of the joint to give rounded corners to your shape. For instance:

pts = RandomReal[{-5, 5}, {20, 2}];
ConvexHullMesh[pts]

hull

Retrieve the mesh expressed as a Polygon object and style to your liking:

Graphics[{
  Darker@Blue, 
  EdgeForm[{Darker@Blue, Thickness[0.09], JoinForm["Round"]}],
  Cases[Normal[chm["Graphics"]], _Polygon, All]
}]

styled

MarcoB
  • 67,153
  • 18
  • 91
  • 189