# Visualize extremal points of 3D function with additional conditions

When looking for the critical points of $f(x,y) = x^6+y^6+x^2+y^2$ only on the set $M = \lbrace (x,y) \in \mathbb{R}^2 \mid x^2+y^2 = 1 \rbrace$ I ask myself for a good visualization. So it would be great to have the 3DPlot of $f$ with all the points on the surface of $f(x,y)$ marked where $(x,y) \in M$.

Something like that:

f[x_, y_] := x^6 + y^6 + x^2 + y^2

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2},
MeshFunctions -> {#^2 + #2^2 &},
Mesh -> {{1}},
MeshStyle -> Directive[Red, Thick]]


Update: Keeping the original mesh lines in a single Plot3D:

Using multiple MeshFunctions:

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2},
MeshFunctions -> {#^2 + #2^2 &, # &, #2 &},
Mesh -> {{1}, 20, 20},
MeshStyle -> {Directive[Red, Thick], Gray, Gray}]


Using two functions as the first argument and using the option BoundaryStyle:

Plot3D[{f[x, y], ConditionalExpression[f[x, y], x^2 + y^2 <= 1]},
{x, -2, 2}, {y, -2,  2}, PlotStyle -> {LightBlue, None},
BoundaryStyle -> {2 -> Directive[Red, Thick]}]


Update 2: to visualize the region $M=\lbrace (x,y) \in \mathbb(R)^2 \mid x^2 + y^2 < 1 \rbrace$:

Plot3D[{ConditionalExpression[f[x, y], x^2 + y^2 >= 1],
ConditionalExpression[f[x, y], x^2 + y^2 <= 1]},
{x, -2, 2}, {y, -2, 2}, PlotStyle -> {LightBlue, Red}]


• Thank you for your help. Jul 1, 2018 at 9:57
• @Arjihad, my pleasure. Thank you for the accept.
– kglr
Jul 1, 2018 at 12:01

Here is a way to get exactly the picture you showed, including the regular mesh lines on the surface:

f[x_, y_] := x^6 + y^6 + x^2 + y^2
surf = Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, PlotTheme -> "Classic"];
intersect =
Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, PlotStyle -> {FaceForm[]},
BoundaryStyle -> None, MeshFunctions -> {#^2 + #2^2 &},
Mesh -> {{1}}, MeshStyle -> Directive[Red, Thickness[.01]]];
Show[surf, intersect]


I used the same trick as @kglr but combined two versions of the plot. One uses the mesh to create the intersection only (no surface), and the other creates only the surface with its regular mesh. To combine them, I use Show, which is really the general way to put any number of 3D plots together as one unit.

• Is there a there a way to visualize the same plot with $M=\lbrace (x,y) \in \mathbb(R)^2 \mid x^2 + y^2 < 1 \rbrace$ ? Jul 1, 2018 at 6:43