My goal is to use ColorFunction
to color a cylinder based on the $z$ value of a separate Plot3D
. I'm not sure if I am making a mathematical error somewhere or if I am just messing up some snippet of the following code.
a = Pi;
b = 2;
f[x_, y_] = y;
u[x_, y_, t_] = -((8 E^(-((π^2 t)/20)) (2 - π) Cos[(π y)/4])/π^2) -
(8 E^(-((π^2 t)/5)) (2 + 3 π) Cos[(3 π y)/4])/(9 π^2) -
(8 E^(-((9 π^2 t)/20)) (2 - 5 π) Cos[(5 π y)/4])/(25 π^2);
Table[ContourPlot[u[x, y, t], {x, -a, a}, {y, 0, b},
ColorFunction -> ColorData["TemperatureMap"],
Contours -> 8], {t, {0, .1, .3, .5, 1, 2, 3, 4}}]
Now, I want to wrap each contour plot onto a cylinder by gluing the $x=-a$ edge to the $x=a$ edge; the bottom of the cylinder is then at $y=0$ and the top at $y=b$.
Table[ParametricPlot3D[{Cos[theta], Sin[theta], rho}, {theta, -Pi, Pi}, {rho, 0, 2},
AxesLabel -> {x, y, z}, ColorFunctionScaling -> False,
ColorFunction -> Function[{x, y, z, theta, rho},
ColorData["TemperatureMap"][u[x, rho, t]]],
Mesh -> 8, MeshFunctions -> {Function[{x, y, z, theta, rho},
f[Cos[theta], rho]]}, ViewPoint -> {-2.3, 0.77, -2},
ViewVertical -> {-0.08, 1, -0.06}],
{t, {0, .1, .3, .5, 1, 2, 3, 4}}]
This is clearly not correct based on what I am after. Where am I going wrong?
I tried turning ColorFunctionScaling
off and on with no luck. I also tried replacing that middle snippet dealing with the coloring with
ColorFunctionScaling -> False,
ColorFunction -> Function[{x, y, z, theta, rho},
ColorData["TemperatureMap"][Rescale[u[Cos[theta], rho, t], {0,2}]]]
where a Plot3D
shows $u(x,y,t)$ ranges over (about) $[0,2]$. I suspect the solution lies in some tweaking of this part.
Answer
You can get the colors from the 2D contour plots and use them as the setting for MeshShading
:
tt = {0, .1, .3, .5, 1, 2, 3, 4};
cps = Table[ContourPlot[u[x, y, t], {x, -a, a}, {y, 0, b},
ColorFunction -> ColorData["TemperatureMap"], Contours -> 8], {t, tt}];
colors = Cases[cps[[#]], _RGBColor, Infinity] & /@ Range[8];
Then
Grid[Partition[Table[ParametricPlot3D[{Cos[theta], Sin[theta], rho},
{theta, -Pi, Pi}, {rho, 0, 2},
Mesh -> 8,
MeshFunctions -> {Function[{x, y, z, theta, rho}, u[x, z, tt[[i]]]]},
MeshShading -> colors[[i]],
ColorFunction -> Function[{x, y, z, theta, rho},
ColorData["TemperatureMap"][u[x, z, tt[[i]]]]],
AxesLabel -> {x, y, z}], {i, Range[8]}], 4]]
gives
Comments
Post a Comment