3
$\begingroup$

Consider the plane $N: x+y+z-3 q=0$ where $q$ is fixed and the sphere $S: (x-q)^2+(y-q)^2+(z-q)^2=r$ where $r$ is fixed.

I would like to make a 3D plot of $N$ and of $S\cap N$.

Here is my command using the BoundaryStyle option. Henter image description hereowever the intersection is poorly represented. I tried to increase to value of PlotPoints but i didn't improve the representation. Any thoughts ?

q = 1/(1+2+1/2)
rN = 0.01
eqS    = (x-q)^2+(q-q)^2+(z-q)^2
eqNcar = x+y+z-3 q
p      = ContourPlot3D[{(eqNcar)==0,eqS==rN},\
  {x,-3,3},{y,-3,3},{z,-3,3},\
  Mesh->None,ContourStyle->{Automatic,None},\
  PlotPoints->100,\
  PlotRange->{{q-0.2,q+0.2},{q-0.2,q+0.2},{q-0.2,q+0.2}},\
  BoundaryStyle->{{1,2}->{Black,Thick}}]
$\endgroup$

2 Answers 2

4
$\begingroup$
  • Using the skill of MeshFunction, set the MeshFunction to eqS and set the Mesh to rN.
Clear["Global`*"];
q = 1/(1 + 2 + 1/2);
rN = 0.01;
eqS = (x - q)^2 + (y - q)^2 + (z - q)^2;
eqNcar = x + y + z - 3 q;
ContourPlot3D[eqNcar == 0, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}, 
 MeshFunctions -> Function[{x, y, z}, Evaluate@eqS], Mesh -> {{rN}}, 
 PlotPoints -> 200, MaxRecursion -> 6, 
 MeshStyle -> Directive[Thick, Cyan], MeshShading -> {Red, Yellow}, 
 PlotRange -> {{q - 0.2, q + 0.2}, {q - 0.2, q + 0.2}, {q - 0.2, 
    q + 0.2}}]

enter image description here

$\endgroup$
2
$\begingroup$

You can also use Region functionality. As an example:

Clear["Global`*"];
q = 1/(1 + 2 + 1/2);
r = 0.01;
reg1 = ImplicitRegion[x + y + z - 3 q == 0, {x, y, z}];
reg2 = Ball[{q, q, q}, Sqrt[r]];
reg3 = Sphere[{q, q, q}, Sqrt[r]];
r2 = RegionIntersection[reg1, reg2];
r3 = RegionIntersection[reg1, reg3];

Show[
 Region[Style[RegionDifference[reg1, r2], Blend[{Cyan, Green}]]
  , PlotRange -> {{q - 2 Sqrt[r], q + 2 Sqrt[r]}
    , {q - 2 Sqrt[r], q + 2 Sqrt[r]}, {q - 2 Sqrt[r], q + 2 Sqrt[r]}
    }]
 , Region[Style[r2, Red]]
 , Region[Style[r3, {Thick, Black}]]
 , Boxed -> True
 , Axes -> True
 , AxesLabel -> {x, y, z}
 , AxesEdge -> {{-1, -1}, {-1, 1}, {-1, -1}}
 , SphericalRegion -> True
 ]

enter image description here

$\endgroup$

Your Answer

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

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