# Generate a table of data points from a surface in 3D

I'm trying to extract the data points from a general 3D surface and saving the data points, in the form of the coordinate triples $$\mathbf{ \{ x,y,z\} }$$, in a table/array in the format: $$\mathbf{\{ \{ x_1,y_1,z_1\} , \{ x_2,y_2,z_2\} , ..., \{ x_n,y_n,z_n\} \} }$$.

With a cylinder this is quite easy since we know that for a cylinder:

$$\mathbf{x^2+y^2=r^2}$$

$$\mathbf{ x=t_1}$$

$$\mathbf{ y=n \cdot \sqrt{r^2-t_1^2}}$$

$$\mathbf{ z=t_2}$$

where $$n$$ is either +1 or -1. So for a cylinder with radius 1 and length 10 we can generate the table as:

step=0.1
data = Table[{x = t1, y = n*(1 - t1^2)^(1/2), z = t2},
{t1, -1, 1,step}, {t2, 0, 10, step}, {n,{-1,1}}];


I would like to know if there exist an easier way to do this? I have tried executing Table[plot] but that doesn't seem to save any data points it just saves the plot itself in the table as an element.

I just started learning Mathematica yesterday so I am a complete beginner, so be easy on me please.

• Do you already have the plot ? Apr 30, 2019 at 15:04
• @b.gatessucks Not for the cylinder. But I do know how to plot the cylinder using RegionPlot3D. Apr 30, 2019 at 15:26
• Just trying to understand: what is plot in your Table[plot] ? Apr 30, 2019 at 15:27
• @b.gatessucks plot = RegionPlot3D[ x^2 + y^2 <= n + 0.1 && x^2 + y^2 >= n, {x, -2, 2}, {y, -2, 2}, {z, -20, 20}, PlotPoints -> 120, ImageSize -> Large], {n, 1, 1.1, 0.1} Apr 30, 2019 at 15:33

Assuming the plot is

plot = With[{n = 1.},
RegionPlot3D[x^2 + y^2 <= n + 0.1 && x^2 + y^2 >= n,
{x, -2, 2}, {y, -2, 2}, {z, -20, 20}, PlotPoints -> 120, ImageSize -> Large]
]


one can extract the discrete points it's made of by taking

points = Cases[plot, GraphicsComplex[p___] :> p, Infinity];


The first element points[[1]] is a list of points as it can be checked:

ListPointPlot3D[points[[1]]]


• I can't seem to recreate the cylinder from points[[1]]. imgur.com/a/0gC1iWw data=points[[1]] ListPlot3D[data, BoxRatios -> Automatic, Mesh -> All] Apr 30, 2019 at 16:21