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}
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}
xy
plane, which is why it does not match up.(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 likepgfplot
, you could also use this answer.)