1
$\begingroup$

This is building on a question previously answered by Rahul recently. I have a particular 3D surface plot on which I wish to delineate where z (the function) is between the corresponding x value and the corresponding y value (i.e., x < z < y OR y < z < x) and where x is between z and y (i.e., z < x < y OR y < x < z). I came up with:

Plot3D[-4.53 + 2.67 x + 2.78 y - 1.09 x y, {x, 1.8, 2.6}, {y, 1.8, 2.6}, PlotRange -> {1.7, 2.6}, Ticks -> {{1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}, {1.8, 2., 2.2, 2.4, 2.6}}, LabelStyle -> Opacity[0], BoxRatios -> Automatic, MeshFunctions -> {Function[{x, y, z}, z - x], Function[{x, y, z}, z - y], Function[{x, y, z}, x - y], Function[{x, y, z}, x - z]}, Mesh -> {{0}, {0}, {0}, {0}}, MeshShading -> None, Lighting -> "Neutral"]

Rahul helped with the first part in which he used MeshFunctions to show where z is between x and y. I tried to build on that for showing where x is between z and y. The problem is that it appears there is no portion where y < x < z. Perhaps that is true -- that such a set of values does not occur for this plot over its plot range, but perhaps I am incorrectly specifying this. Also, I cannot for the life of me figure out how to do MeshShading to shade each of the regions; thus I left it as "None." But ideally, I would uniquely color each part. Thank you in advance.

$\endgroup$
2
$\begingroup$

EDIT: Corrected error by adding ColorFunctionScaling -> False

f[x_, y_] = -4.53 + 2.67 x + 2.78 y - 1.09 x y //
    Rationalize // Simplify;

Plot3D[f[x, y],
 {x, 1.8, 2.6}, {y, 1.8, 2.6},
 PlotRange -> {1.7, 2.6},
 PlotPoints -> 101,
 AxesLabel ->
  (Style[#, Bold, 14] & /@ {"x", "y", "z"}),
 Ticks ->
  {{1.8, 2., 2.2, 2.4, 2.6},
   {1.8, 2., 2.2, 2.4, 2.6},
   {1.8, 2., 2.2, 2.4, 2.6}},
 BoxRatios -> {1, 1, 1},
 ColorFunction ->
  Function[{x, y, z},
   Piecewise[
    {{Blue, (x < z < y) || (y < z < x)},
     {Red, (z < x < y) || (y < x < z)}},
    Green]],
 ColorFunctionScaling -> False]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks much, Bob Hanlon, for your help on this. I might be confused or maybe I inadvertently gave incorrect information, but the lines your formula drew to make the divisions look incorrect. Take for example the large area defined by the largest green section. Except for a very small portion of this near the lower tip (x and y roughly equal to 1.85 and 1.85), all of this AND most of the blue rectangle above it should be blue, not green, as for the majority of this area, z is between x and y. This is correctly indicated in the division specified in MY formula (with help from Rahul). $\endgroup$ – kwsockman Nov 30 '14 at 10:26
  • $\begingroup$ I agree that coloring was wrong. I forgot to turn off the ColorFunctionScaling. Corrected above. $\endgroup$ – Bob Hanlon Nov 30 '14 at 16:34
  • $\begingroup$ Perfect, Bob Hanlon. Thank you so much. -- Keith $\endgroup$ – kwsockman Nov 30 '14 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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