0
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ Do you already have the plot ? $\endgroup$ Apr 30, 2019 at 15:04
  • $\begingroup$ @b.gatessucks Not for the cylinder. But I do know how to plot the cylinder using RegionPlot3D. $\endgroup$ Apr 30, 2019 at 15:26
  • $\begingroup$ Just trying to understand: what is plot in your Table[plot] ? $\endgroup$ Apr 30, 2019 at 15:27
  • $\begingroup$ @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} $\endgroup$ Apr 30, 2019 at 15:33

1 Answer 1

1
$\begingroup$

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]]]

plot

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.