18

7

Extending from these questions How to check if a 3D point is in a planar polygon? and How to check if a 2D point is in a polygon?.

I'm trying to do this to render specific shapes made up of spheres.

For a sphere it is easy:

```
(* generate a grid of points*)
d = 20;
points = Table[{x, y, z}, {x, -d, d}, {y, -d, d}, {z, -d, d}]~Flatten~2;
(*check if they are inside a spherical shell*)
points2 = Select[points, 8.5 < Norm[#] < 10 &];
(*render the spheres that are inside the spherical shell*)
Graphics3D[{Sphere[#, 0.75]} & /@ points2, Boxed -> False]
```

However, I want to try and do the same rendering for other shapes, for example a pentagonal dipyramid

```
Graphics3D[{Lighter@Lighter@Blue, Opacity[.8], EdgeForm[Thickness[ 0.005]], PolyhedronData["PentagonalDipyramid", "Faces"]}, Boxed -> False]
```

However, I'm not sure how to check if the points on the grid are with in the polyhedron.

I can access the faces... `PolyhedronData["PentagonalDipyramid", "Faces"]`

2Generating convex polyhedron from face planes is closely related because when the planes' normal vectors are consistently oriented, they provide a simple mechanism for determining whether points are inside or outside (as illustrated, for instance, in the code in my answer in that thread: see the argument to the

`RegionPlot3D`

example there). – whuber – 2012-11-25T23:07:26.397The RedionFunction approach is quite good. In cases where there are many small faces you might instead consider shooting a ray to the outside and counting intersections. For this to be effective you'd need to bin faces in such a way that most never get tested for intersection, that is, only "reasonable contenders" get tested. – Daniel Lichtblau – 2012-11-26T04:15:38.567