How to “merge” various graphics 2d into one 3d graphic? [duplicate]

This question already has an answer here:

Plotting several functions

5 answers

I did some calculations and as result got a 2D graphic, but at the beginning of the work I used a constant parameter. What I want is to make a 3D graphic with this parameter as an axis, varying from 1 to 100. How to proceed?

=================

=================

1 Answer
1

=================

Generally speaking Mathematica has 3D versions of everything, so you are probably best to use those from the start. But if you really want to convert 2D to 3D, then you could do it with a set of rules:

Clear[linerule];
linerule[z_] := Line[points_, stuff___] :> Line[{First@#, Last@#, z} & /@ points, stuff];
Clear[textrule];
textrule[z_] := Text[t_, {x_, y_}, stuff___] :> Text[t, {x, y, z}, stuff];
(* pointRule, graphicsComplexRule, polygonRule, etc. *)
Clear[allrules];
allrules[z_] := {linerule[z], textrule[z]};

It’s not so simple as taking a list of two numbers to a list of three. Sometimes your list of two numbers might not be a 2D point. So these rules specifically target the bits which we know are coordinates. Some primitives like Circle are going to be more that just appending a z coordinate.

As an example use:

Clear[p];
p[z_] := Plot[(x – z)^2, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}, PlotStyle -> Thick];

Graphics3D[
Table[First@FullGraphics@p[z] /. allrules[z], {z, 0, 1, 0.2}]
, Boxed -> False]

  

 

In routine maintenance I was preparing to delete this old closed question, but your answer seems interesting. Since the question is otherwise abandoned would you consider editing it to specifically fit this answer, or reposting this in a self-Q&A?
– Mr.Wizard♦
Jul 25 ’15 at 13:46