Points In/Out in 3D shapes

• To: mathgroup at smc.vnet.net
• Subject: [mg101163] Points In/Out in 3D shapes
• From: M <xrayspectrum at googlemail.com>
• Date: Thu, 25 Jun 2009 07:16:12 -0400 (EDT)

```Hallo All Mathematica gurus,
I have the following code which helps to find if a point is inside or
outside the 2D polygon.

pnPoly[{testx_, testy_}, pts_List] :=
Xor @@ ((Xor[#[[1, 2]] > testy, #[[2, 2]] >
testy] && ((testx - #[[2,
1]]) < (#[[1, 1]] - #[[2,
1]]) (testy - #[[2, 2]])/(#[[1, 2]] - #[[2, 2]]))) & /@
Partition[pts, 2, 1, {2, 2}])

pol = {{-1, -1}, {0, 0}, {1, -1}, {0, 1}, {1, 0}};
Graphics[{PointSize[Large], {FaceForm[LightGray], EdgeForm[Black],
Polygon[pol]},
If[pnPoly[#, pol], {Blue, Point[#]}, {Red, Point[#]}] & /@
RandomReal[{-1, 1}, {400, 2}]}]
Clear[pol]

Ok. this works really good!.
How can I test if a random point is inside or outside in a given
volume of any 3D shaped object.
I need to count the points that are inside the volume. Any
suggestons ?

Thank you in advance

```

• Prev by Date: Re: Take away the sliders
• Next by Date: Re: Take away the sliders
• Previous by thread: Re: Plot with x value in Log
• Next by thread: Re: Points In/Out in 3D shapes