# Help understanding options on ContourPlot3D

I am creating some figures showing the intersection between two surfaces. I managed to get most of what I want with the following code:

ContourPlot3D[{z == g[x, y], z == g[p, q]},
{x, -1, 1}, {y, 0.11, 2}, {z, 0, 3},
ContourStyle -> {Directive[GrayLevel[0.71], Opacity[1]],
Directive[Blue, Opacity[0.2]]},
Mesh -> None,
BoundaryStyle -> {2 -> None, {1, 2} -> {Blue, Thick}, 1 -> None}];


I need help in understanding this line BoundaryStyle -> {2 -> None, {1, 2} -> {Blue, Thick}, 1 -> None}. I want to change some options on one surface but not the other and I suspect that deciphering this line will show me how to do other stuff I want. I realize that I am undoubtedly missing some things about the Mathematica language broadly speaking, but I can't seem to find exactly what I'm looking for, just bits and pieces that I haven't been able to piece together.

AFAIK the Mathematica documentation is silent on the variant of the BoundaryStyle option you are asking about. Based on my experience, here is how I think it works.

The BoundaryStyle option specifies how the edges of the intersections of two surfaces in a plot are colored. When only one surface is specified the second surface is taken to be the edges of the clipping region of the plot with the indicated surface. In this case, its behavior heavily depends on what clipping regions appear in the plot.

The 1st case is simple. The option takes the form

{sufrace_indicator, sufrace_indicator} -> directives


where the sufrace_indicator stands for the ordinal number a surface in the fir1stst argument given to the plot function. Therefore, in your code

{1, 2} -> {Blue, Thick}


means show the intersection of the 1st surface and 2nd surface as a thick, blue curve.

In the 2nd case the option takes the for

sufrace_indicator -> directives


where sufrace_indicator is the same as in the 1st case and the clipping regions determined by Mathematica when it parses the arguments that appear after the 1st argument. Therefore, in your code

2 -> {Green, Thick}


means show the intersections of the 2nd surface (the plane) with the plot's bounding box as think, green lines.

However, the clipping region does not have to be the plot's bounding box. It can be explicitly specified. Here is an example where the clipping region is a cylinder.

Plot3D[{g[x, y], f[x, y]}, {x, y} ∈ Disk[{0, 1}, 1],
PlotRange -> {0, 3},
BoxRatios -> {1, 1, 1},
Mesh -> None,
PlotStyle -> {{Black, Opacity[.25]}, {Blue, Opacity[.25]}},
ClippingStyle -> {{Green, Opacity[.2]}, {Yellow, Opacity[.2]}},
BoundaryStyle -> {1 -> {Yellow, Thick}, {1, 2} -> {Blue, Thick}, 2 -> {Green, Thick}}]


• Thank you that is helpful. In trying to understand the syntax better, can I interpret this line: ClippingStyle -> {{Green, Opacity[.2]}, {Yellow, Opacity[.2]}}' as equivalent to ClippingStyle -> {1->{Green, Opacity[.2]}, 2->{Yellow, Opacity[.2]}}' ? Nov 6, 2020 at 23:33
• @CharlieH.. No. ClippingStyle uses a different syntax. Click on the link int the previous sentence and read the Details section. Nov 6, 2020 at 23:53

This work?

g[u_, v_] := u^2 + v^2;
f[p_, q_] := p - q + 2;
ContourPlot3D[{z == g[x, y], z == f[x, y]}, {x, -1, 1}, {y, 0.11,
2}, {z, 0, 3},
ContourStyle -> {Directive[GrayLevel[0.71], Opacity[1]],
Directive[Blue, Opacity[0.2]]}, Mesh -> None,
BoundaryStyle -> {1 -> {Yellow, Thick}, {1, 2} -> {Blue, Thick},
2 -> {Green, Thick}}]


In the BoundaryStyle,

1 indicate the boundary of the first surface z==g[x,y],here we set Yellow;

2 indicate the boundary of the second surface z==f[x,y],here we set Green;

{1,2} indicate the intersection of the two surfaces,here you set Blue

We can test another example.

ContourPlot3D[{x^2 + y^2 + z^2 == 1, x^2 + y^2 == 1/2}, {x, -1,
1}, {y, -1, 1}, {z, -1, 1},
ContourStyle -> {Directive[GrayLevel[0.71], Opacity[1]],
Directive[Blue, Opacity[0.2]]}, Mesh -> None,
BoundaryStyle -> {1 -> {Yellow, Thick}, {1, 2} -> {Blue, Thick},
2 -> {Green, Thick}}]


• I appreciate the response, but it doesn't really answer my question. I'm able to get the intersection of surfaces like you posted, but I'm really looking for an understanding of the syntax in the BoundaryStyle line. Nov 5, 2020 at 23:38
• @CharlieH. I have updated the answer :-) Nov 5, 2020 at 23:57
• That does help, thank you. I am able to change boundary properties for individual surfaces/intersections. I was wondering though if something similar might be used to add mesh lines to one surface and not the other? I thought that would use a similar syntax to the BoundaryStyle but I can't seem to get it working. Nov 6, 2020 at 23:29
• @CharlieH. This can be done by use MeshFunctions and Mesh, I will updated my answer later. Nov 6, 2020 at 23:45
• @CharlieH. For example, g[u_, v_] := u^2 + v^2; f[p_, q_] := p - q + 1; ContourPlot3D[z == g[x, y], {x, -1, 1}, {y, 0.11, 2}, {z, 0, 3}, MeshFunctions -> Function[{x, y, z}, z - f[x, y]], Mesh -> {{0, 1, 2, 3, 4}}, ContourStyle -> {Directive[GrayLevel[0.71], Opacity[1]], Directive[Blue, Opacity[0.2]]}, BoundaryStyle -> {1 -> {Yellow, Thick}, {1, 2} -> Blue, 2 -> {Green, Thick}}] Nov 6, 2020 at 23:59