Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a ListlinePlot function, that I would like to combine with both a Graphics3D plot and a ListPointPlot3D plot, in such a way that the ListLinePlot is the bottom of the 3D boundary cube for the 3D plots. Can this be done in Mathematica 8.0.4?

Obviously the code below fails to combine the plots in Show, but is there another way to accomplish this? Thanks!

    Needs["TetGenLink`"]
twodPts = RandomReal[{-1, 1}, {10, 2}];
threedPts = RandomReal[{-1, 1}, {50, 3}];
{pts, surface} = TetGenConvexHull[threedPts];

twoDptsPlot = ListLinePlot[twodPts, ImageSize -> {200, 200}];
threeDPtsPlot = ListPointPlot3D[threedPts, ImageSize -> {200, 200}];
surfacePlot = 
  Graphics3D[{EdgeForm[], Opacity[0.3], 
    GraphicsComplex[pts, Polygon[surface]], ImageSize -> {200, 200}}];

{twoDptsPlot, 
 Show[threeDPtsPlot, surfacePlot, ImageSize -> {200, 200}, 
  BoxRatios -> 1, Axes -> False]}

Mathematica graphics

share|improve this question
1  
I've edited your code a bit, and included some figure, please feel free to roll back if you don't agree with the change in the Show line. –  István Zachar Mar 29 '12 at 13:08
    
I seem to remember we have had the same type of question before, perhaps on SO/mathematica. Can't find it at the moment. One easy approach would be to Texture a plane with the 2D plot. –  Sjoerd C. de Vries Mar 29 '12 at 13:16
2  
this question might help –  Heike Mar 29 '12 at 13:55
add comment

4 Answers

up vote 19 down vote accepted

The following is probably what you want.

Make3d[plot_, height_, opacity_] := 
  Module[{newplot},
    newplot = First@Graphics[plot]; 
    newplot = N@newplot /. {x_?AtomQ, y_?AtomQ} :> {x, y, height};
    newplot /. GraphicsComplex[xx__] :> {Opacity[opacity], GraphicsComplex[xx]}
  ]

Show[{Graphics3D[Make3d[twoDptsPlot, -1, .75]], threeDPtsPlot,surfacePlot}, Axes -> True]

which gives enter image description here

This function can takes any 2D plot and place it on a 3D box with a specified height. I got this trick in the web few years back but now cant remember the reference. Hope this helps you.

share|improve this answer
1  
+1, I had typed out a similar answer before seeing this... –  acl Mar 29 '12 at 13:58
1  
I saw the method in this a while ago. mathgis.blogspot.com/2009/02/howto-display-2d-plot-in-3d.html –  Ajasja Mar 29 '12 at 14:10
    
@Ajasja You are right this is the link I was looking for.. –  PlatoManiac Mar 29 '12 at 14:17
    
Thanks Very Much! Excellent solution! –  R Hall Mar 29 '12 at 14:29
add comment

This is an approach that uses the graphics primitive Line.

Needs["TetGenLink`"]
twodPts = Transpose[{RandomReal[{-1, 1}, {10}], RandomReal[{-1, 1}, {10}], 
    Table[-1, {10}]}];
threedPts = RandomReal[{-1, 1}, {50, 3}];
{pts, surface} = TetGenConvexHull[threedPts];
twoDptsPlot = Graphics3D[Line[twodPts], PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
    ImageSize -> {200, 200}];
threeDPtsPlot = ListPointPlot3D[threedPts, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
    ImageSize -> {200, 200}];
surfacePlot = Graphics3D[{EdgeForm[], Opacity[0.3], GraphicsComplex[pts, Polygon[surface]],
    PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
    ImageSize -> {200, 200}}];
Show[threeDPtsPlot, surfacePlot, twoDptsPlot, ImageSize -> {200, 200},
    BoxRatios -> 1, Axes -> False]

enter image description here

share|improve this answer
    
Very Cool! Thanks very much! –  R Hall Mar 29 '12 at 14:30
add comment

You explicitly ask for the ListLinePlot to be placed in the Graphics3D, not just the lines contained in the plot. Since none of the answers so far do that here is my version.

surfacePlot = 
 Graphics3D[{EdgeForm[], {Texture[twoDptsPlot], 
    Polygon[{{-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}}, 
     VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, 
     {Opacity[0.3], GraphicsComplex[pts, Polygon[surface]]}}, 
   ImageSize -> 400, 
   Lighting -> "Neutral"]

Show[surfacePlot, threeDPtsPlot, Axes -> False]

Mathematica graphics

share|improve this answer
    
This looks like a cool approach @Sjoerd C. de Vries, thanks for the great code! –  R Hall Mar 29 '12 at 22:23
1  
Might want to use Texture[ImageData[Rasterize[twoDptsPlot, Background -> None]]] if you need the texture to have transparency. –  Brett Champion Mar 30 '12 at 2:28
add comment

Just in case using a single Graphics3D may be of interest:

Graphics3D[{
  PointSize[.01], Red, Point /@ threedPts, 
  Blue, Thickness[.003], Line@(Insert[#, -1, -1] & /@ twodPts), 
  GraphicsComplex[pts, {EdgeForm[], FaceForm[{Pink, Opacity[0.4]}], Polygon[surface]}], 
  ImageSize -> {200, 200}
}]

gives

enter image description here

share|improve this answer
    
Some amazing answers here! Thanks so much! –  R Hall Mar 31 '12 at 16:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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