Because the question refers to points using both Cartesian coordinates $(x,y,z)$ and spherical coordinates $(\theta, \phi)$, we need to convert between them:
spherical[{x_, y_, z_}] := {ArcTan[z, Norm[{x, y}]], ArcTan[x, y]};
A point p
is inside the "hole" when its distance from the origin (computed with Norm
) is less than the value given by the function radius
. For flexibility, I have included an optional argument threshold
that multiplies the value of radius
:
inside[p_, origin_, radius_, threshold_: 1] :=
threshold radius @ spherical @ (p - origin) >= Norm[p - origin];
Use this to Select
the points inside the hole (or, by negating inside
, to exclude them):
pointsInside = Select[points, inside[#, origin = {0, 0, 0}, radius] &];
(I have chosen an origin of {0,0,0}
for this example to make it easy to plot the hole using SphericalPlot3D
.)
Example
Let's define a hole to illustrate:
radius[{\[Theta]_, \[Phi]_}] := (1 + Cos[\[Theta]]^2) (1 + Sin[ \[Phi]]^2);
We will need some points:
points = RandomReal[NormalDistribution[0, 1], {3000, 3}];
For the illustration, let's plot all those points, distinguishing those inside the hole from those outside it:
pointPlot = Graphics3D[{Opacity[0.3], Gray, Point @ points,
PointSize[0.01], Red, Opacity[0.5], Point @ pointsInside,
Black, Opacity[1], Point @ origin}];
Here is the hole's boundary for reference:
hole = SphericalPlot3D[radius[{\[Theta], \[Phi]}], {\[Theta], 0, \[Pi]}, {\[Phi], 0, 2 \[Pi]},
PlotStyle -> Opacity[0.25], Mesh -> None]
Put them together:
Show[pointPlot, hole]

Select
orDeleteCases
,EuclideanDistance
orNorm
... For instance, using these, here's a box of points with the points falling within a sphere of radius 1/Sqrt@2 and center (1,1,1) missing i.stack.imgur.com/Rkoc7.png $\endgroup$DeleteCases[points, p_ /; EuclideanDistance[p, {1, 2, 3}] < 10]
$\endgroup$Norm
orEuclideanDistance
. $\endgroup$