拥有 TikZ 或tikz-euclide
生成具有连续内切圆到三角形的图片而无需计算每个小三角形的点的最简单方法是什么?
我有以下代码,其中有一个三角形的两个内切圆。如果我想继续或自动绘制不同的三角形,该怎么办?
\begin{tikzpicture}
\draw ({-sqrt(3)},-1) -- ({(1-sqrt(3))/2}, {(1+sqrt(3))/2}) -- ({2+sqrt(3)},-1) -- ({-sqrt(3)},-1) ;
\draw (0,0) circle [radius=1];
\tkzDefPoint(3.7,-1){A}
\tkzDefPoint(1.16452,0.482362){B}
\tkzDefPoint(0.767327,-1){C}
\tkzDrawSegments(A,B B,C C,A)
\tkzDefCircle[in](A,B,C)\tkzGetPoint{I}\tkzGetLength{rIN}
\tkzDrawCircle[R](I,\rIN pt)
\end{tikzpicture}
谢谢!
答案1
我理解你的问题,认为新的三角形与旧的三角形相似。你的例子在这一点上有所不同。
只需一点工作,您就可以创建一个图像,该图像在每一侧以及圆圈本身都完成了递归。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,through}
\makeatletter
\pgfmathdeclarefunction{tikzveclen}{2}{%
\begingroup
% \pgfpointdiff{\tikz@scan@one@point\pgfutil@firstofone(#1)}
% {\tikz@scan@one@point\pgfutil@firstofone(#2)}%
\pgfpointdiff{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}%
\edef\pgfmath@temp{{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}}%
\expandafter\pgfmathveclen@\pgfmath@temp
\pgfmath@smuggleone\pgfmathresult
\endgroup}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=4]
\path (0,0) coordinate (A) + (0:3) coordinate (B) +(60:1) coordinate (C);
\draw (A) -- (B) -- (C) -- cycle;
\foreach \cnt in {1,...,10}{
\pgfmathsetmacro\triA{tikzveclen("B","C")}
\pgfmathsetmacro\triB{tikzveclen("C","A")}
\pgfmathsetmacro\triC{tikzveclen("A","B")}
%\pgfmathsetmacro\triS{.5*\triA+.5*\triB+.5*\triC}
%\pgfmathsetlengthmacro\triRadius{sqrt((\triS-\triA)/\triS*(\triS-\triB)*(\triS-\triC))}
\path (barycentric cs:A=\triA,B=\triB,C=\triC) coordinate (M)
node [draw, circle through=($(A)!(M)!(C)$)] (M) {};
% or: circle[radius=\triRadius]
\draw ($(C)-(A)$) coordinate (vecB)
(M.60-90) coordinate (@) % or: ([shift=(60-90:\triRadius)] M) coordinate (@)
(intersection of @--[shift=(vecB)]@ and B--C) coordinate (C) --
(intersection of @--[shift=(vecB)]@ and B--A) coordinate (A);
}
\end{tikzpicture}
\end{document}
输出
答案2
使用math
库(cvs-version)很容易:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}
\foreach \i [remember=\r (initially 3)] in {1,2,...,5}{
\draw (0,0) circle (\r);
\draw (90:\r) -- (-30:\r)--(210:\r)--cycle;
\tikzmath{
\r=\r*sin(30);
}
}
\end{tikzpicture}
\end{document}
编辑
这是 TiKZ 2.10 的有效解决方案。它使用through
库。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle (3cm);
\coordinate (a) at (90:3);
\coordinate (b) at (-30:3);
\coordinate (c) at (210:3);
\foreach \in in {1,2,...,5}
{
\node[circle through=(a),draw] {};
\draw (a)--(b)--(c)--cycle;
\coordinate(aux) at (a);
\path (a)--(b) coordinate[pos=.5] (a);
\path (b)--(c) coordinate[pos=.5] (b);
\path (c)--(aux) coordinate[pos=.5] (c);
}
\end{tikzpicture}
\end{document}