0
$\begingroup$

Consider the following example data which creates the lines of a cylinder

data=Table[{Cos[phi],Sin[phi],z},{phi,0,2Pi,.1},{z,0,1,.1}];
Graphics3D[{RandomChoice[ColorData[3,"ColorList"]],Line[#]}&/@data]

enter image description here

The coloring indicates the structure of data which is a list of lines where with lines I mean a list of {x,y,z} coordinates. Therefore, data is of dimension {63, 11, 3}: 63 lines where each line as 11 points.

With the legacy package of older Mathematica versions it was now possible to create the surface of the cylinder by

Needs ["Graphics` Graphics3D `"]
ListSurfacePlot3D[data]

If you look on the usage of the built-in ListSurfacePlot3D function you see that it can only take a list of 3D points and not such a structured tensor as data. When you then try it anyway, you get a surprising result:

ListSurfacePlot3D[data]

enter image description here

Question: is it possible to create the surface of the cylinder like the old version of ListSurfacePlot3D did?

On this simple examples, a call to

ListSurfacePlot3D[Flatten[data, 1]]

helps. Unfortunately, for my original data here, this doesn't work. You can recreate the error by shearing the cylinder data

data = Table[
   {Cos[phi] + 2 z, z, Sin[phi] + z}, {phi, 0, 2 Pi, .1}, {z, -2, 
    2, .1}];
Graphics3D[{RandomChoice[ColorData[3, "ColorList"]], Line[#]} & /@ 
   data]
ListSurfacePlot3D[Flatten[data, 1]]

and then you get

enter image description here

$\endgroup$
4
  • 2
    $\begingroup$ The link provided doesn't explain the problem your trying to solve. Please edit and explain that in your question above. thank you $\endgroup$ Commented May 1, 2013 at 14:53
  • $\begingroup$ @chuy Please see my edit $\endgroup$
    – halirutan
    Commented May 1, 2013 at 16:47
  • $\begingroup$ really cool edit, sorry for my lazy work, I'm freshman of this website, I'll take some time to get familar with the comuunity about learn to edit and express problems clearly. $\endgroup$ Commented May 2, 2013 at 6:56
  • $\begingroup$ @HyperGroups Welcome to Mma.SE!!! $\endgroup$
    – mmjang
    Commented May 2, 2013 at 10:46

2 Answers 2

2
$\begingroup$

The first thing I tried was to Flatten your data, so that it is a flat list of 3D coordinates. When you take your simple cylinder example and apply for instance a shearing transformation, you see, that you cannot rely on what ListSurfacePlot3D is doing.

Not only that it does not reconstruct your whole cylinder points, furthermore it gets really messy when the shearing kicks in:

With[{data = Flatten[Table[
     {Cos[phi], Sin[phi], z}, {phi, 0, 2 Pi, .1}, {z, -1, 1, .1}], 1]},

 Manipulate[
  Show[
     ListSurfacePlot3D[#],
     Graphics3D[{AbsolutePointSize[1], Red, Point[#]}],
     PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}, PlotRangePadding -> .5
     ] &[
   ShearingTransform[phi, {1, 0, 0}, {0, 0, 1}][data]],
  {phi, 0, Pi/2}]
 ]

enter image description here

If you want to have the behavior of the old ListSurfacePlot3D back, you could investigate in the AddOns/LegacyPackages/Graphics directory of a version 8 installation and extract the important code:

MakePolygons[vl_List] := 
 Module[{l = vl, l1 = Map[RotateLeft, vl], mesh}, 
  mesh = {l, l1, RotateLeft[l1], RotateLeft[l]};
  mesh = Map[Drop[#, -1] &, mesh, {1}];
  mesh = Map[Drop[#, -1] &, mesh, {2}];
  Polygon /@ Transpose[Map[Flatten[#, 1] &, mesh]]]

ListSurfacePlot3DOld[data_, opts : OptionsPattern[]] := 
 Graphics3D[MakePolygons[data], 
  Evaluate[FilterRules[{opts}, Options[ListSurfacePlot3D]]]]

And now, everything should work as expected

ListSurfacePlot3DOld[data, Axes -> False]

enter image description here

$\endgroup$
4
  • $\begingroup$ I, for one, downvoted the question. I don't consider my decision annoying, but I feel the question really is. $\endgroup$ Commented May 1, 2013 at 15:58
  • $\begingroup$ @belisarius So it is obvious and not worth investigating, why ListSurfacePlot3D changed its behavior? Because this is what the question is: How handled the old function tensors of dimensions {n1,n2,3} and why can the new function only handle tensors of dimensions {n,3}? $\endgroup$
    – halirutan
    Commented May 1, 2013 at 16:06
  • $\begingroup$ No, please don't misunderstand me. The question could certainly be the most important thing after vacuum cleaners. But if I can't figure out what the OP is talking about after a few minutes I begin to suspect something is wrong .. $\endgroup$ Commented May 1, 2013 at 16:13
  • $\begingroup$ @chuy Unfortunately, this does not work on the original data. This was my first guess too and for the simplified example it works. I edited the question again and pointed this out. $\endgroup$
    – halirutan
    Commented May 1, 2013 at 16:36
3
$\begingroup$

I can't really blame the OP. After all, the docs here so glibly recommend that one now do ListSurfacePlot3D[Flatten[pts, 1]] where one once needed to do ListSurfacePlot3D[pts].

We could, as halirutan did in his answer, grab the old routine from the package Graphics`Graphics3D` and just use it again in the new Mathematica. Or, we could exploit the fact that Mathematica now has GraphicsComplex[], which lets us write a modernized version of Roman Maeder's MakePolygons[]:

MakePolygons[vl_] := Module[{dims = Most[Dimensions[vl]]}, 
  GraphicsComplex[Apply[Join, vl], Polygon[Flatten[Apply[Join[#1, Reverse[#2]] &, 
                  Partition[Partition[Range[Times @@ dims], Last[dims]], {2, 2}, {1, 1}],
                        {2}], 1]]]] /; ArrayQ[vl, 3]

which we can now use to turn the array of points into a nice pile of Polygon[]s:

data = Table[N[{2 z + Cos[φ], z, z + Sin[φ]}], {φ, 0, 2 π, π/30}, {z, -2, 2, 1/10}];

Graphics3D[MakePolygons[data]]

skewed cylinder

One does lose out on the options supported by the new ListSurfacePlot3D[] like coloring or texturing, but this might be offset by the comfort of seeing Mathematica dutifully render the mesh you expected and were supposed to see.

$\endgroup$
1

Your Answer

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

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