6

I am trying draw a circle is intersection of a plane has equation 2 x − 2 y + z − 15 = 0 and the equation of the sphere is ( x − 1)^2 + ( y + 1)^ 2 + ( z − 2)^ 2 − 25 = 0. enter image description here

The plane cut the sphere is a circle with centre (3,-3,3 and radius r = 4.

I can't draw the circle. I tried

\documentclass[12pt,border = 2 mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[tdplot_main_coords]
\path
      coordinate (T) at (3,-3,3)
      coordinate (I) at (1,-1,2);

\foreach \v/\position in {T/above,I/below} {
    \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}

\draw[dashed] (T) circle[radius={4}];

\begin{scope}[tdplot_screen_coords, on background layer]
  \pgfmathsetmacro{\R}{5}%
  \fill[ball color=purple, opacity=1.0] (I) circle (\R); 
\end{scope}
\end{tikzpicture}
\end{document} 

enter image description here

How can I draw the circle?

  • I guess the issue is rather basic: you need to specify the plane in which the circle is in. Your plane has a nontrivial normal vector but you draw the circle in the xy plane, which is why it does not match up. – user121799 Mar 25 '19 at 1:36
  • The plane has normal vector is (2,-2,1). – minhthien_2016 Mar 25 '19 at 1:38
  • Yes, I know. Naively I would think that it is better to switch to a local coordinate system in which the center of the sphere is at (0,0,0) and the normal goes in the z direction, and then just rotate the view. Do your know this nice answer. It will allow you to draw the intersection in such a way that the visible stretch is distinguished from the hidden one. (If you do not like pgfplot, you could also use this answer.) – user121799 Mar 25 '19 at 1:41
6

We know the normal n of the plane and the radius of the circle. Call two vectors that are orthogonal to n and orthogonal to each other u and v. Then the circle is given by

 gamma(t) = I + n + r * cos(t) * u + r* sin(t) * v,

where n fulfills the length constraint n^2+r^2=R^2, where R is the radius of the sphere and r the radius of the circle. Your vector n satisfies this constraint already, so we do not have to change its normalization.

Now we need to figure out what the visible and invisible stretches are. Any point on the sphere has either a positive or negative projection on the normal vector on the screen

n_screen =({sin(\tdplotmaintheta)*sin(\tdplotmainphi)},{-sin(\tdplotmaintheta)*cos(\tdplotmainphi)},{cos(\tdplotmaintheta)});

So we need to find the zeros of the projection gamma(t).n_screen. This can be accomplished by letting TikZ find the intersections. Of course we do not really draw the paths here, and use overlay for them not to screw up the bounding box. Notice that the current version assumes that there are two zeros, so if you drastically change the view angles, this version won't work any more.

\documentclass[12pt,border=2mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds,intersections}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[tdplot_main_coords,
declare function={dicri(\t,\th,\ph,\R)=
sin(\th)*sin(\ph)*(2+\R*cos(\t)*1/sqrt(2)+\R*sin(\t)*1/sqrt(18))-
sin(\th)*cos(\ph)*(-2+\R*cos(\t)*1/sqrt(2)-\R*sin(\t)*1/sqrt(18))+
cos(\th)*(1-4*\R*sin(\t)*1/sqrt(18));}]
\path
      coordinate (T) at (3,-3,3)
      coordinate (I) at (1,-1,2)
      coordinate (n) at (2,-2,1)
      coordinate (u) at ({1/sqrt(2)},{1/sqrt(2)},0)
      coordinate (v) at ({1/sqrt(18)},{-1/sqrt(18)},{-4/sqrt(18)});
      % the coordinatesn, u and v are not really used here

\foreach \v/\position in {T/above,I/below} {
    \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
% \draw[red,thick,-latex] (0,0,0) --
% ({sin(\tdplotmaintheta)*sin(\tdplotmainphi)},
% {-sin(\tdplotmaintheta)*cos(\tdplotmainphi)},{cos(\tdplotmaintheta)});
% normal to screen
\begin{scope}[tdplot_screen_coords, on background layer]
  \pgfmathsetmacro{\R}{5}%
  \fill[ball color=purple, opacity=1.0] (I) circle (\R);
  % determine the zeros of dicri
  \path[overlay,name path=dicri] plot[variable=\x,domain=0:360,samples=73]
  ({\x*1pt},{dicri(\x,\tdplotmaintheta,\tdplotmainphi,4)});
  \path[overlay,name path=zero] (0,0) -- (360pt,0);
  \path[name intersections={of=dicri and zero,total=\t}]
  let \p1=(intersection-1),\p2=(intersection-2) in
  \pgfextra{\xdef\xmin{\x1}\xdef\xmax{\x2}};
\end{scope}
\pgfmathsetmacro{\R}{4}
\draw[dashed] plot[variable=\t,domain=\xmin:\xmax,samples=73,smooth] 
 ({1+2+\R*cos(\t)*1/sqrt(2)+\R*sin(\t)*1/sqrt(18)},
 {-1-2+\R*cos(\t)*1/sqrt(2)-\R*sin(\t)*1/sqrt(18)},
 {2+1-4*\R*sin(\t)*1/sqrt(18)});
\draw[thick] plot[variable=\t,domain=\xmax:\xmin+360,samples=73,smooth] 
 ({1+2+\R*cos(\t)*1/sqrt(2)+\R*sin(\t)*1/sqrt(18)},
 {-1-2+\R*cos(\t)*1/sqrt(2)-\R*sin(\t)*1/sqrt(18)},
 {2+1-4*\R*sin(\t)*1/sqrt(18)});
\end{tikzpicture}
\end{document}

enter image description here

And here is a plane, using your nicer vectors u and v from the chat.

\documentclass[12pt,border=2mm,tikz]{standalone} 
\usepackage{tikz-3dplot} 
\usetikzlibrary{arrows,calc,backgrounds,intersections} 
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\begin{document} 
\tdplotsetmaincoords{60}{110} 
\begin{tikzpicture}[tdplot_main_coords, 
  declare function={dicri(\t,\th,\ph,\R)=% 
  sin(\th)*sin(\ph)*(2+\R*cos(\t)/3+2*\R*sin(\t)/3)-%
  sin(\th)*cos(\ph)*(-2 +2*\R*cos(\t)/3 + \R*sin(\t)/3)+%
  cos(\th)*(1+2*\R*cos(\t)/3-2*\R*sin(\t)/3);}] 
  \pgfmathsetmacro{\R}{5}% 
  \path  coordinate (T) at (3,-3,3) 
   coordinate (I) at (1,-1,2) 
   coordinate (n) at (2,-2,1) 
   coordinate (u) at (1, 2, 2) 
   coordinate (v) at (2, 1, -2); 
  % the coordinatesn, u and v are not really used here 
   \path[tdplot_screen_coords,shift={(I)},use as bounding box] (-1.2*\R,-1.2*\R)rectangle (1.2*\R,1.2*\R);   

  \foreach \v/\position in {T/above,I/below} { 
   \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$}; 
  } 
  % \draw[red,thick,-latex] (0,0,0) -- 
  % ({sin(\tdplotmaintheta)*sin(\tdplotmainphi)}, 
  % {-sin(\tdplotmaintheta)*cos(\tdplotmainphi)},{cos(\tdplotmaintheta)}); 
  % normal to screen 
  \begin{scope}[tdplot_screen_coords, on background layer] 
   \fill[ball color=green, opacity=0.8] (I) circle (\R); 
   % determine the zeros of dicri 
   \path[overlay,name path=dicri] plot[variable=\x,domain=0:360,samples=73] 
   ({\x*1pt},{dicri(\x,\tdplotmaintheta,\tdplotmainphi,4)}); 
   \path[overlay,name path=zero] (0,0) -- (360pt,0); 
   \path[name intersections={of=dicri and zero,total=\t}] 
   let \p1=(intersection-1),\p2=(intersection-2) in 
   \pgfextra{\xdef\tmin{\x1}\xdef\tmax{\x2}}; 
  \end{scope} 
  \pgfmathsetmacro{\SmallR}{4} 
  \draw[dashed] plot[variable=\t,domain=\tmin:\tmax,samples=50,smooth] 
   ({1+2+\SmallR*cos(\t)/3+2*\SmallR*sin(\t)/3}, 
   {-1-2 +2*\SmallR*cos(\t)/3+ \SmallR*sin(\t)/3}, 
   {2+1+2*\SmallR*cos(\t)/3 - 2*\SmallR*sin(\t)/3 }); 
  \draw[thick,save path=\pathA] plot[variable=\t,domain=\tmax:\tmin+360,samples=50,smooth] 
   ({1+2+\SmallR*cos(\t)/3+2*\SmallR*sin(\t)/3}, 
   {-1-2 +2*\SmallR*cos(\t)/3+ \SmallR*sin(\t)/3}, 
   {2+1+2*\SmallR*cos(\t)/3 - 2*\SmallR*sin(\t)/3 }); 
  \path ({1+2+\SmallR*cos(\tmin)/3+2*\SmallR*sin(\tmin)/3}, 
   {-1-2 +2*\SmallR*cos(\tmin)/3+ \SmallR*sin(\tmin)/3}, 
   {2+1+2*\SmallR*cos(\tmin)/3 - 2*\SmallR*sin(\tmin)/3 }) coordinate (pmin)
   ({1+2+\SmallR*cos(\tmax)/3+2*\SmallR*sin(\tmax)/3}, 
   {-1-2 +2*\SmallR*cos(\tmax)/3+ \SmallR*sin(\tmax)/3}, 
   {2+1+2*\SmallR*cos(\tmax)/3 - 2*\SmallR*sin(\tmax)/3 }) coordinate (pmax);
  \begin{scope}[tdplot_screen_coords]
   \clip[shift={(I)}] (-1.2*\R,-1.2*\R)rectangle (1.2*\R,1.2*\R);   
   \path[fill=gray,fill opacity=0.4,even odd rule] let \p1=($(pmin)-(I)$),\p2=($(pmax)-(I)$),
   \p3=($(pmax)-(pmin)$),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},
   \n3={atan2(\y3,\x3)}
    in [use path=\pathA]  (pmin) arc(\n1:\n2-360:\R) 
    (0,-6) -- ++(\n3:{12cm/sin(\n3)}) -- ++(\n3+90:{12cm/sin(\n3)})
    -- ++(\n3+180:{12cm/sin(\n3)}) -- cycle;
  \end{scope}
\end{tikzpicture} 
\end{document}

enter image description here

  • How can I find the points u and v? The way to find. – minhthien_2016 Mar 25 '19 at 4:16
  • @minhthien_2016 They need to be orthogonal to n and to each other. – user121799 Mar 25 '19 at 4:18
  • And how about the number 4.01? – minhthien_2016 Mar 25 '19 at 4:23
  • 1
    I can find u = (1, -4, -10) and v = (8, 7, -2). – minhthien_2016 Mar 25 '19 at 4:25
  • Can we reduce the line ({1+2+4.01*cos(\t)*1/sqrt(2)+4.01*sin(\t)*1/sqrt(18)}, {-1-2+4.01*cos(\t)*1/sqrt(2)-4.01*sin(\t)*1/sqrt(18)}, {2+1-4*4.01*sin(\t)*1/sqrt(18)}) as I + n + 4.01* cos(t) * u + 4.01*sin(\t)*v? – minhthien_2016 Mar 25 '19 at 4:34
6

Many thanks to Schrödinger's cat about 3dtools. In this answer, I use Mathematica to find coordinates of three points A, B, C and draw circle (ABC). I use tikz-3dplot-circleofsphere at here to draw style of line of the circle (ABC).

\documentclass[12pt,tikz,border=2 mm]{standalone}
\usepackage{tikz-3dplot-circleofsphere}
\usetikzlibrary{3dtools}
\begin{document}
    \tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=1,tdplot_main_coords,declare function={R=5;
}]
    \path   (3,-3,3) coordinate (T)
    (1,-1,2) coordinate (I) 
    (1, {1/5 *(-23 - 2* sqrt(11))}, {1/5 *(19 - 4 *sqrt(11))}) coordinate (A)
    (1, {1/5 *(-23 + 2* sqrt(11))}, {1/5 *(19 + 4 *sqrt(11))}) coordinate (B)
    ({1/4* (13 + sqrt(119))}, {1/4 *(-13 + sqrt(119))}, 2) coordinate (C);
\begin{scope}[tdplot_screen_coords] 
\fill[ball color=green, opacity=0.8] (I) circle (R);
    \end{scope}
\begin{scope}[shift={(I)}]
\path[overlay] [3d coordinate={(A-B)=(A)-(B)},
3d coordinate={(A-C)=(A)-(C)},
3d coordinate={(myn)=(A-B)x(A-C)},
3d coordinate={(A-T)=(A)-(T)}];
\pgfmathsetmacro{\myaxisangles}{axisangles("(myn)")}
\pgfmathsetmacro{\myalpha}{{\myaxisangles}[0]}
\pgfmathsetmacro{\mybeta}{{\myaxisangles}[1]}
\pgfmathsetmacro{\mygamma}{-acos(sqrt(TD("(A-T)o(A-T)"))/R)}
\tdplotCsDrawCircle[tdplotCsFront/.style={thick}]{R}{\myalpha}{\mybeta}{\mygamma} 
\end{scope} 

\foreach \p in {I,T,B}
\draw[fill=black] (\p) circle (1.5 pt);
\foreach \p/\g in {I/0,T/-90,B/30}
\path (\p)+(\g:3mm) node{$\p$};
\draw[dashed] (I) -- (T) -- (B) -- cycle;
    \end{tikzpicture}
\end{document} 

enter image description here

3

I add this because you asked me to use the 3d circle through 3 points pic here. It can be used after we have three points. These points can be constructed by adding vectors of length 4, the radius, to T which lie in the plane of the circle. These vectors are taken from the other answer, and rescaled.

\documentclass[12pt,tikz,border=2 mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools,backgrounds}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[tdplot_main_coords]
\pgfmathsetmacro{\mysq}{4/3}
\path   (3,-3,3) coordinate (T)
      (1,-1,2) coordinate (I) 
      (1, 2, 2) coordinate (u)  
      (2, 1, -2) coordinate (v)
      [3d coordinate={(A)=(T)+\mysq*(u)}]
      [3d coordinate={(B)=(T)+\mysq*(v)}]
      [3d coordinate={(C)=(T)-\mysq*(u)}];

\foreach \v/\position in {T/above,I/below} {
    \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}

\path[dashed] pic{3d circle through 3 points={A={(A)},B={(B)},C={(C)}}};

\begin{scope}[tdplot_screen_coords, on background layer]
  \pgfmathsetmacro{\R}{5}%
  \fill[ball color=purple, opacity=1.0] (I) circle (\R); 
\end{scope}
\end{tikzpicture}
\end{document} 

enter image description here

  • You wrote pgfmathsetmacro{\mysq}{4/3}. How can I find the number 4/3? – minhthien_2016 Apr 16 '20 at 18:42
  • @minhthien_2016 If I remember correctly they were chosen such that A, B and C sit on the sphere, i.e. (A-I)^2=5^2 and so on. – user194703 Apr 16 '20 at 18:52
  • Schrödinger's cat Perhaps, it's r/IH. We can use Mathematica to find coordinates of three points A, B, C. – minhthien_2016 Apr 17 '20 at 2:32
  • @minhthien_2016 The factor 4/3 is very simple. We want (T+a u-I)^2=5^2. Since (T-I) is perpendicular to u, this means that (T-I)^2+a^2 u^2=9 (1+a^2)=25, or a^2=(25-9)/9=16/9, so a=4/3. – user194703 Apr 17 '20 at 4:06
  • Now I see. Thanks. – minhthien_2016 Apr 17 '20 at 4:13
3

As an alternative, Asymptote version:

// spherexplane.asy
//
// run 
//   asy -f pdf -render=4 -noprc spherexplane.asy
// to get a standalone raster spherexplane.pdf
//
import solids;
size(8cm); size3(100,100);
currentprojection=orthographic(camera=(66,40,-9),zoom=0.9);
currentlight=Headlamp;

pen linePen=darkblue+1.3bp;
pen dotPen= darkblue+3bp;
pen dashPen=1bp+linetype(new real[]{4,3})+linecap(0);

// Eqn of the sphere (x - 1)^2 + (y + 1)^ 2 + (z - 2)^ 2 - 25 = 0
triple O=(1,-1,2);
real R=5;

// Eqn of the plane  2 x - 2 y + z - 15 = 0
triple fp(real x, real y){return (x,y,- 2 x + 2 y + 15);}

triple Np=unit((2,-2,1)); // plane normal
triple A=fp(0,0);  // any point on the plane
triple C=O+dot(A-O,Np)*Np; // center of the circle cross section

real d=abs(C-O);
real r=sqrt(R^2-d^2);

guide3 baseArc=Arc(O,O+Np*R,O-Np*R,normal=cross(Z,Np));
revolution b=revolution(O,baseArc,axis=Np); // spherical surface
skeleton s;
real t=acos(d/R)/pi; // fraction of the arc length at the cutting point
b.transverse(s,reltime(b.g,t),P=currentprojection);
guide3 circCut=s.transverse.back[0] & s.transverse.front[0] & cycle;

triple D=relpoint(circCut,0.6);

draw(surface(b),paleblue+opacity(0.3));
draw(surface(circCut),orange+opacity(0.3));

draw(s.transverse.front,linePen);
draw(s.transverse.back, dashPen);

draw(O--C--D, dashPen);

dot("$O$",O,dotPen);
dot(Label("$C$",unit(C-O)),C,dotPen);
dot("$D$",D,dotPen);

xaxis3(xmin=0,xmax=1,red,above=true);
yaxis3(ymin=0,ymax=1,deepgreen,above=true);
zaxis3(zmin=0,zmax=1,blue,above=true);

enter image description here

  • +1, I am still learning your asymptote answers. – Nguyen Van Chi Oct 31 '20 at 11:33
  • Thank you very much. – minhthien_2016 Oct 31 '20 at 12:30
  • @g.kov Does asymptote always draw the hidden parts dashed automatically? – minhthien_2016 Dec 19 '20 at 14:59
  • @minhthien_2016: I don't think it does. – g.kov Dec 19 '20 at 16:44
  • @g.kov Is Asymptote Is real 3D and TikZ Is not? – minhthien_2016 Dec 20 '20 at 14:01

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.