2
$\begingroup$

Here are three pieces of code that can draw 3D curves and are successfully used for {x^2 + y^2 == 1, 2x + 3z == 6}:

(1)

Clear["Global`*"];
h =x^2 + y^2 -1;
g =2*x + 3*z - 6;
ContourPlot3D[{h == 0, g == 0}, {x, -2, 2}, {y, -2, 2}, {z, 0, 4}, 
 MeshFunctions -> {Function[{x, y, z, f}, h - g]}, 
 MeshStyle -> {{Thick, Blue}}, Mesh -> {{0}}, 
 ContourStyle -> 
  Directive[Orange, Opacity[0.5], Specularity[White, 30]]]

(2)

Clear["Global`*"];
reg = ImplicitRegion[{x^2 + y^2 == 1, 2*x + 3*z == 6}, {x, y, z}];
Region[reg, BoxRatios -> {1, 1, 1}, Boxed -> True, 
 PlotRange -> {{-2, 2}, {-2, 2}, {0, 4}}, Axes -> True, 
 AspectRatio -> 1, AxesOrigin -> {0, 0, 0}, AxesLabel -> {x, y, z}]

(3)

Clear["Global`*"]; 
ContourPlot3D[{x^2 + y^2 == 1, 
    2*x + 3*z == 6}, {x, #, #2}, {y, #3, #4}, {z, #5, #6}, Mesh -> 1, 
   ImageSize -> 500, BaseStyle -> 18, ViewPoint -> {5, 1, 2}, 
   ContourStyle -> (Directive @@@ {{Red}, {Green}, {Blue, 
        [email protected]}, {Yellow}}), Lighting -> "Neutral", 
   AxesLabel -> {"x", "y", "z"}] & @@@ {{-2, 2, -2, 2, 0, 4}}

However, there are some errors when drawing 3D curves {z == Sqrt[16 - x^2 - y^2], (x - 2)^2 + y^2 == 4}:

(1)

Clear["Global`*"];
h = z - Sqrt[16 - x^2 - y^2];
g = (x - 2)^2 + y^2 - 4;
ContourPlot3D[{h == 0, g == 0}, {x, -1, 5}, {y, -3, 3}, {z, -1, 5}, 
 AxesLabel -> {x, y, z}, 
 MeshFunctions -> {Function[{x, y, z, f}, h - g]}, 
 MeshStyle -> {{Thick, Blue}}, Mesh -> {{0}}, 
 ContourStyle -> 
  Directive[Orange, Opacity[0.5], Specularity[White, 30]]]

(The surface has some irregular bulges and some irregular curves)

(2)

Clear["Global`*"];
reg = ImplicitRegion[{z == Sqrt[16 - x^2 - y^2], (x - 2)^2 + y^2 == 
     4}, {x, y, z}];
Region[reg, BoxRatios -> {1, 1, 1}, Boxed -> True, 
 PlotRange -> {{-1, 5}, {-3, 3}, {-1, 5}}, Axes -> True, 
 AspectRatio -> 1, AxesOrigin -> {0, 0, 0}, AxesLabel -> {x, y, z}]

(The curve cannot be seen)

(3)

Clear["Global`*"]; 
ContourPlot3D[{z == Sqrt[16 - x^2 - y^2], (x - 2)^2 + y^2 == 
     4}, {x, #, #2}, {y, #3, #4}, {z, #5, #6}, Mesh -> 1, 
   ImageSize -> 500, BaseStyle -> 18, ViewPoint -> {5, 1, 2}, 
   ContourStyle -> (Directive @@@ {{Red}, {Green}, {Blue, 
        [email protected]}, {Yellow}}), Lighting -> "Neutral", 
   AxesLabel -> {"x", "y", "z"}] & @@@ {{-1, 5, -3, 3, -1, 5}}

(The underside of the surface is not smooth)

How to solve these problems?

$\endgroup$

1 Answer 1

5
$\begingroup$

One way is avoid Sqrt.

Clear[reg];
reg = ImplicitRegion[{z^2 == 16 - x^2 - y^2, (x - 2)^2 + y^2 == 
    4}, {x, y, z}]
Region[Style[reg, Directive[Thick, Red]], BoxRatios -> {1, 1, 1}, 
 Boxed -> True, PlotRange -> {{-1, 5}, {-3, 3}, {-1, 5}}, 
 Axes -> True, AspectRatio -> 1, AxesOrigin -> {0, 0, 0}, 
 AxesLabel -> {x, y, z}]

enter image description here

ContourPlot3D[{z^2 == 16 - x^2 - y^2, (x - 2)^2 + y^2 == 
     4}, {x, #, #2}, {y, #3, #4}, {z, #5, #6}, Mesh -> 1, 
   ImageSize -> 500, ViewPoint -> {5, 1, 2}, 
   ContourStyle -> (Directive @@@ {{Red}, {Green}, {Blue, 
        [email protected]}, {Yellow}}), Lighting -> "Neutral", 
   AxesLabel -> {"x", "y", "z"}, PlotPoints -> 50] & @@@ {{-1, 5, -3, 
   3, -1, 5}}
Clear[h, g];
h = z^2 - (16 - x^2 - y^2);
g = (x - 2)^2 + y^2 - 4;
ContourPlot3D[{h == 0, g == 0}, {x, -1, 5}, {y, -3, 3}, {z, -1, 5}, 
 AxesLabel -> {x, y, z}, 
 MeshFunctions -> {Function[{x, y, z, f}, h - g]}, 
 MeshStyle -> {{Thick, Blue}}, Mesh -> {{0}}, 
 ContourStyle -> 
  Directive[Orange, Opacity[0.5], Specularity[White, 30]]]
$\endgroup$
5
  • $\begingroup$ Thank you. z>0. The region should be" ImplicitRegion[{z^2 == 16 - x^2 - y^2, (x - 2)^2 + y^2 == 4, z > 0}, {x, y, z}]". But how to set the function value to Z > 0 in ContourPlot3d? @cvgmt $\endgroup$
    – lotus2019
    Feb 17, 2022 at 6:22
  • $\begingroup$ @lotus2019 Remove PlotRange -> {{-1, 5}, {-3, 3}, {-1, 5}} $\endgroup$
    – cvgmt
    Feb 17, 2022 at 11:06
  • $\begingroup$ Thank you. How to set the function value to Z > 0 in ContourPlot3D?@cvgmt $\endgroup$
    – lotus2019
    Feb 18, 2022 at 2:41
  • $\begingroup$ @lotus2019 RegionFunction -> Function[{x, y, z}, z > 0], RegionBoundaryStyle -> None $\endgroup$
    – cvgmt
    Feb 18, 2022 at 2:46
  • $\begingroup$ Thank you! @cvgmt $\endgroup$
    – lotus2019
    Feb 18, 2022 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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