我正在尝试绘制一个圆与平面的交点有方程2 x − 2 y + z − 15 = 0
,而球体的方程是( x − 1)^2 + ( y + 1)^ 2 + ( z − 2)^ 2 − 25 = 0
。
平面切球体为一个圆,其圆心为(3,-3,3
,半径为r = 4
。
我不能画圆。我试过了
\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}
我怎样才能画圆圈?
答案1
我们知道n
平面的法线和圆的半径。设两个n
相互正交的向量分别为u
和v
。则圆的半径为
gamma(t) = I + n + r * cos(t) * u + r* sin(t) * v,
其中n
满足长度约束n^2+r^2=R^2
,其中R
是球体的半径和r
圆的半径。您的向量n
已经满足此约束,因此我们不必更改其规范化。
现在我们需要弄清楚可见和不可见的拉伸是什么。球体上的任何一点在屏幕上的法向量上都有正投影或负投影
n_screen =({sin(\tdplotmaintheta)*sin(\tdplotmainphi)},{-sin(\tdplotmaintheta)*cos(\tdplotmainphi)},{cos(\tdplotmaintheta)});
因此我们需要找到投影的零点gamma(t).n_screen
。这可以通过让 Ti 来实现钾Z 找到交点。当然,我们在这里并不真正绘制路径,而是使用overlay
它们来避免弄乱边界框。请注意,当前版本假设有两个零,因此如果您大幅改变视角,此版本将不再起作用。
\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}
这是一架飞机,使用你更好的矢量u
和v
从聊天。
\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}
答案2
非常感谢薛定谔的猫3dtools
。在这个答案中,我使用数学找到三个点的坐标A, B, C
并画圆(ABC)。我tikz-3dplot-circleofsphere
使用 这里绘制圆的线条样式(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}
答案3
我之所以添加这个,是因为你让我在这里使用3d circle through 3 points
图片。我们有三个点后就可以使用它了。这些点可以通过添加长度为 4 的向量(半径)来构造,这些T
向量位于圆的平面上。这些向量取自另一个答案,并重新缩放。
\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}
答案4
我是 3dtools
这样使用的。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=110,theta=70},line cap=butt,line join=round,declare function={R=5;},c/.style={circle,fill,inner sep=1pt}]
\path[overlay]
(0,0,15) coordinate (A)
(1,-1,2) coordinate (I);
\draw[3d/screen coords] (I) circle[radius=R];
\path[overlay,3d/plane with normal={(2,-2,1) through (A) named p}];
\path[3d/project={(I) on p}] coordinate (T);
\pic{3d/circle on sphere={R=R,C={(I)}, P={(T)}}};
\path foreach \p/\g in {I/-90,T/90}
{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
\end{tikzpicture}
\end{document}