Re: Points In/Out in 3D shapes

• To: mathgroup at smc.vnet.net
• Subject: [mg101206] Re: Points In/Out in 3D shapes
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Fri, 26 Jun 2009 06:54:27 -0400 (EDT)
• Organization: Uni Leipzig
• References: <h1vm8i\$afl\$1@smc.vnet.net>

```Hi,

if your shaped object is an implicit function like
x^2+y^2+z^2-1  for a sphere of radius 1 than the sign
of this implicit function serve as inside/ outside indicator.
If you object is build up from tetrahedrons you mist check if
the point is in one of the tetrahedrons.
If you have just the surface of the 3d object you must
split the object into tetrahedrons first.

Regards
Jens
M wrote:
> 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 ?
>
>