| Author |
Comment/Response |
KB
|
06/25/09 03:12am
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!.
But when i have a 3D polygon how can I test if a random point is inside or outside the volume.
I need to count the points that are inside the Volume of any irregular shape. Any suggestons ?
Thank you in advance
KB
URL: , |
|