Edit: This question turned out to be two parts so I am going to make this question about only the first part a kguler provided an excellent answer.
Here is a better representation. My actual data consists of many points which I bin onto a grid.
data = RandomVariate[NormalDistribution[1, 3], {10^5, 3}];
rounded = Round@data;
gathered = Gather[rounded];
offset = -Min /@ Transpose@rounded + 1;
counts = Length /@ gathered;
(*I offset the data so I can use SparseArray from 1*)
coords = offset + # & /@ (First /@ gathered);
sparesearray = SparseArray[coords -> counts];
Each grid contains the count of the number of points that were in the grid cube (voxel). I now create a contour plot.
ListContourPlot3D[sparesearray, Contours -> {2.5}]
In this case its ugly since its random data. However, in my real data it has discrete volumes. I want to find the points in the original data (or the offset data).
I could simply use the bins with more than n
counts but I was hoping to take advantage of the interpolation that ListContourPlot3D
uses.
How do I extract the polygons rendered by ListContourPlot3D
?
early version below for posterity:
I have a set of data points in 3D and I want to extract the subset of points that is contained within the surface generated by a contour plot.
data = Table[x^2 + y^2 + z^2 + RandomReal[0.1], {x, -2, 2, 0.2}, {y, -2, 2,
0.2}, {z, -2, 2, 0.2}]
The sample data here is on a regular grid but my real data is not on a regular grid. It is defined: (x, y, z, value)
.
plot = ListContourPlot3D[data, Contours -> {1}, Mesh -> None]
InputForm
returns a GraphicsComplex
object but I'm not really sure how to determine the polygons in the surface and then how to determine which of the points are inside the surface and which are outside.
{x,y,z}
points from your dataset for whichvalue
is in a given range? (For your example $\text{value} \in [0,1]$ because the contour is at $1$) $\endgroup$