![在 TikZ 图上绘制三条切线到圆周上的特定点](https://linux22.com/image/471548/%E5%9C%A8%20TikZ%20%E5%9B%BE%E4%B8%8A%E7%BB%98%E5%88%B6%E4%B8%89%E6%9D%A1%E5%88%87%E7%BA%BF%E5%88%B0%E5%9C%86%E5%91%A8%E4%B8%8A%E7%9A%84%E7%89%B9%E5%AE%9A%E7%82%B9.png)
如何绘制下面 TikZ 图片中所示的三条红线:
第 1 行:从内圆 0 度圆周开始,沿切线向北延伸,到达中间圆。将数字“20”放置在此行的中点。
线 2:从中圆 180 度圆周开始,沿切线向南延伸,并连接到中圆。将数字“21”放置在此线的中点。
线 3:从内圆 270 度圆周开始,沿切线向东延伸,到达外圆。将字母“x”放置在此线的中点。
请参阅下面的图画以了解详情。
代码:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle (1);
\draw (0,0) circle (2);
\draw (0,0) circle (2.7);
\end{tikzpicture}
\end{document}
输出(红线和字符仅用于说明):
最终作品(感谢社区):
答案1
正如评论中提到的,这本质上只是勾股定理的一个实际例子(请注意,我移动了标签,使它们不被圆圈切开,但显示了$x$
如何使用将标签定位在中间midway
):
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle[radius=1];
\draw (0,0) circle[radius=2];
\draw (0,0) circle[radius=2.7];
\draw[red, densely dotted] (3,0) -- (-3,0);
\draw[red, densely dotted] (0,3) -- (0,-3);
% a^2 + b^2 = c^2 <=> b = (c^2 - a^2)^0.5
\draw[red, thick] (1,0) -- (1,{sqrt(2*2-1*1)})
node[pos=0.75, left] {20};
\draw[red, thick] (0,-1) -- ({sqrt(2.7*2.7-1*1)},-1)
node[pos=0.5, above] {$x$};
\draw[red, thick] (-2,0) -- (-2,{-1*sqrt(2.7*2.7-2*2)})
node[pos=0.25, left] {21};
\end{tikzpicture}
\end{document}
图解:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}[opacity=0.25]
\draw (0,0) circle[radius=1];
\draw (0,0) circle[radius=2];
\draw (0,0) circle[radius=2.7];
\draw[red, densely dotted] (3,0) -- (-3,0);
\draw[red, densely dotted] (0,3) -- (0,-3);
\draw[red, thick] (1,0) -- (1,{sqrt(2*2-1*1)})
node[pos=0.75, left] {20};
\draw[red, thick] (0,-1) -- ({sqrt(2.7*2.7-1*1)},-1)
node[pos=0.5, above] {$x$};
\draw[red, thick] (-2,0) -- (-2,{-1*sqrt(2.7*2.7-2*2)})
node[pos=0.25, left] {21};
\end{scope}
\draw[red] (-2,{-1*sqrt(2.7*2.7-2*2)})
|- node[pos=0.25, left] {$b = \sqrt{c^{2} - a^{2}}$}
node[pos=0.75, above] {$a = 2$} (0,0)
-- node[below right] {$c = 2.7$} cycle;
\draw[red, very thin] (-2,-0.25) -| (-1.75,0);
\end{tikzpicture}
\end{document}
奖励:使用包装的完全相同的图纸l3draw
(标签的位置可能略有不同):
\documentclass[border=10pt]{standalone}
\usepackage{l3draw}
\begin{document}
\ExplSyntaxOn
\draw_begin:
\draw_path_circle:nn { 0cm , 0cm } { 1cm }
\draw_path_circle:nn { 0cm , 0cm } { 2cm }
\draw_path_circle:nn { 0cm , 0cm } { 2.7cm }
\draw_path_use_clear:n { stroke }
\color_select:n { red }
\draw_scope_begin:
\draw_dash_pattern:nn { 1pt } { 0cm }
\draw_path_moveto:n { 3cm , 0cm }
\draw_path_lineto:n { -3cm , 0cm }
\draw_path_moveto:n { 0cm , 3cm }
\draw_path_lineto:n { 0cm , -3cm }
\draw_path_use_clear:n { stroke }
\draw_scope_end:
\draw_linewidth:n { 0.8pt }
\draw_path_moveto:n { 1cm , 0cm }
\draw_path_lineto:n { 1cm , sqrt(2^2 - 1^2) * 1cm }
\draw_path_use_clear:n { stroke }
\draw_scope_begin:
\hcoffin_set:Nn \l_tmpa_coffin { 20 }
\draw_transform_shift:n { 0.9cm , sqrt(2^2 - 1^2) * 0.75cm }
\draw_coffin_use:Nnn \l_tmpa_coffin { r } { vc }
\draw_scope_end:
\draw_path_moveto:n { 0cm , -1cm }
\draw_path_lineto:n { sqrt(2.7^2 - 1^2) * 1cm , -1cm }
\draw_path_use_clear:n { stroke }
\draw_scope_begin:
\hcoffin_set:Nn \l_tmpa_coffin { $x$ }
\draw_transform_shift:n { sqrt(2.7^2 - 1^2) * 0.5cm , -0.9cm }
\draw_coffin_use:Nnn \l_tmpa_coffin { hc } { b }
\draw_scope_end:
\draw_path_moveto:n { -2cm , 0cm }
\draw_path_lineto:n { -2cm , sqrt(2.7^2 - 2^2) * -1cm }
\draw_path_use_clear:n { stroke }
\draw_scope_begin:
\hcoffin_set:Nn \l_tmpa_coffin { 21 }
\draw_transform_shift:n { -2.1cm , sqrt(2.7^2 - 2^2) * -0.25cm }
\draw_coffin_use:Nnn \l_tmpa_coffin { r } { vc }
\draw_scope_end:
\draw_end:
\ExplSyntaxOff
\end{document}
答案2
这是一个解决方案,其中底层驱动程序(此处为 PDF)通过将彩色线条剪切到圆圈来为您完成计算。
路径的顺序是,所有彩色线条都在圆圈后面。当然,这样,节点的位置需要稍微估计一下,但这里很简单。
如果您需要在直线与圆圈相切的点处添加箭头,或者需要绘制另一条线,则必须参与数学运算(由您或 TikZ 完成)。
代码
\documentclass[tikz]{standalone}
\begin{document}
\tikz
\draw[every edge/.append style={densely dotted, red}]
(left:3) edge (right:3)
(down:3) edge (up:3)
(0,0) circle[radius=2.7]
[path picture={
\draw[green] (left:2) -- node[near start,left] {$21$} +(down:2.7);
\draw[red] (down:1) -- node[above] {$x$} +(right:2.7);
\draw (0,0) circle[radius=2]
[path picture={
\draw[blue] (right:1) -- node[right] {$20$} +(up:2);
}];
\draw (0,0) circle[radius=1];
}];
\end{document}
输出
答案3
% !TEX TS-program = lualatex
\documentclass{standalone}
\usepackage{tkz-euclide,tkz-elements}
\begin{document}
\begin{tkzelements}
function pytha (a,b)
return math.sqrt(a*a-b*b)
end
ra,rb,rc = 1,2,2.7
z.O = point : new ( 0 , 0 )
z.A = point : new ( ra , 0 )
z.B = point : new ( 0 , -ra )
z.C = point : new ( -rb , 0 )
z.D = point : new ( rc , 0 )
z.Ap = z.A : north (pytha(rb,ra))
z.Bp = z.B : east (pytha(rc,ra))
z.Cp = z.C : south (pytha(rc,rb))
\end{tkzelements}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawCircles(O,A O,C O,D)
\tkzDrawSegments[red,thick](A,A' B,B' C,C')
\tkzLabelSegment[red,above](B,B'){$x$}
\tkzLabelSegment[red,right](A,A'){$20$}
\tkzLabelSegment[red,left](C,C') {$21$}
\draw[red, densely dotted] (3,0) -- (-3,0)
(0,3) -- (0,-3);
\end{tikzpicture}
\end{document}