# Plotting surfaces in 4D

So I am new to Mathematica and I will probably express myself badly, please let me know if I should specify the problem better.

I have the following constraints over the list {a,b,c,d}:

a=f[c,d]
b=g[c,d]


So that effectively I have {f[c,d],g[c,d],c,d} and I would like to plot this in a 3D+Color graph, with possibly one of the functions as color. I tried various combinations of Table and ListDensityPlot3D but I wasn't able to reach anything (apart from a sparsely colored cube).

Moreover, I have a second surface {f2[c,d], g2[c,d],c,d}, is it possible to plot the two together and possibly find intersection points?

Thanks for the help.

• I would just use ListContourPlot to plot f[c,d] with one style and g[c,d] with another style. You do not need any fancy 3D plots for that. – yarchik Aug 13 '20 at 21:01
• use ListPlot3D to f and g – cvgmt Aug 14 '20 at 1:30
• Unfortunately it is really crucial to me having the two "functions" as two different coordinates in a 4D surface, since they are constraints on them rather than individual functions. The problem is simply that I have a two degrees-of-freedom object in 4D – Thanatopseustes Aug 14 '20 at 7:16
• Could you provide a minimal sample function and explain what you are trying to get with that? – Sumit Aug 14 '20 at 14:16

You can parametrically plot the three dimensional vector $$(f,g,c)$$ sweeping out a two dimensional surface parametrized by c and d, with color dependent on d. If you have two such plots, you can combine them. One way to implement this is

p1 = ParametricPlot3D[{f1[x, y], g1[x, y], x}, {x, -10, 10}, {y, -20, 20}, ColorFunction -> (Hue[#5, 1/2, 1] &), BoxRatios -> {1, 1, 1}]

p2 = ParametricPlot3D[{f2[x, y], g2[x, y], x}, {x, -10, 10}, {y, -20, 20}, ColorFunction -> (Hue[#5, 1, 1] &), BoxRatios -> {1, 1, 1}];

Show[p1, p2]


where I just made some choice for the ranges etc. I use color in the form of Hue to label the value of my variable $$y$$ ($$d$$ for you), which is the fifth argument in the conventions for Colorfunction in ParametricPlot3D in Mathematica, hence the #5 in pure function notation. The second argument of Hue sets saturation, which I use to be able to visually distinguish between the two plots -- this way the one with half saturation one looks "dimmer". The Show command displays both graphs at the same time.

For illustration, I used

f1[x_, y_] := x + y

g1[x_, y_] := x/y

f2[x_, y_] := 2 x + y

g2[x_, y_] := x/y - 3


in the above code, to get Intersections you can try to determine either analytically or numerically, depending on the form of the functions $$f$$ and $$g$$, by hand or using other parts of Mathematica. Visually this is difficult in 4D, as you would need to make sure the colors are exactly matched as well.

• Of course, you can change which parts of {f,h,c,d} you put in the three dimensional vector, and which one you label by color, depending on your needs. – Stijn Aug 14 '20 at 14:34
• Thanks, it works perfectly! This by itself is the answer... however, if I wanted to be superannoying, what is the proper way in order to have one of the two functions as the color function? I mean setting Hue[#1, 1/2, 1] and changing the order does the trick? I sense not judging by your explanation (which was very insightful as well, thanks). Your comments implies it is possible, but I am not sure I understand properly how to implement it. – Thanatopseustes Aug 15 '20 at 0:35
• First, I just edited my answer: I realized to use y (d) as the variable determining color, the argument of the colorfunction should be #5, not #4. I forgot to take into account that ParametricPlot3D has an extra dimension compared to normal ParametricPlot. – Stijn Aug 16 '20 at 11:12
• @Thanatopseustes As for your question, in general you want to represent four parametrically varying real numbers visually: we want to "label" four things. We can put three of them in a vector in three dimensional space. This vector we can then let vary parametrically to get a line (1 parameter), a surface (2 parameters, your case), or, less visually useful, a volume (3 parameters). To add a fourth thing/object/dimension to this, we can use color as you suggested, letting the color of a point on our surface in 3D depend on the fourth dimension. /part1 – Stijn Aug 16 '20 at 11:19
• The parts that are represented by the 3 axes in three dimensions, are determined by which parts you put in which part of the vector. The part represented by color, depends on your assignment of the Colorfunction. You can in principle assign any of them in any way you like, however some cases are easier in Mathematica. The two parametric variables in ParametricPlot3D can be given directly as arguments of the colorfunction (as #4 and #5 respectively), so you could for instance replace x by y in the vector in my example, and #5 by #4, to represent y by "height" and x by color. /part2 – Stijn Aug 16 '20 at 11:23