我正在尝试重新绘制此图像(来源) 在 TikZ 中。
下面是我的具有任意底边长度的三角形的代码(只需直接构造):
\begin{tikzpicture}[x=1mm, y=1mm]
% Base length
\def\l{40}
\draw[line width=0.1mm] (0, 0) -- (\l, 0) -- (0.5*\l, {0.5*\l*tan(72)}) -- cycle;
% y = tan(36)x
\draw[line width=0.1mm, domain=0:{0.25*(1+sqrt(5))*\l}] plot(\x, {tan(36)*\x});
% y = tan(144)x - tan(144)*\l
\draw[line width=0.1mm, domain={0.5*\l}:\l] plot(\x, {tan(144)*\x - tan(144)*\l});
% y = tan(252)x + (tan(36)*0.25*(1+sqrt(5))*\l - tan(252)*(0.25*(1+sqrt(5))*\l)
\pgfmathsetmacro{\p}{((tan(36)*0.25*(1+sqrt(5))*\l - tan(252)*(0.25*(1+sqrt(5))*\l) + tan(144)*\l)/(tan(144) - tan(252))}
\pgfmathsetmacro{\q}{0.25*(1+sqrt(5))*\l}
\draw[line width=0.1mm, domain={\p}:{\q}] plot(\x, {tan(252)*\x + tan(36)*0.25*(1+sqrt(5))*\l - tan(252)*0.25*(1+sqrt(5))*\l});
% y = tan(36)*0.5*\l
\pgfmathsetmacro{\p}{(tan(36)*0.5*\l + tan(252)*0.25*(1+sqrt(5))*\l - tan(36)*0.25*(1+sqrt(5))*\l)/(tan(252))}
\draw[line width=0.1mm, domain={0.5*\l}:{\p}] plot(\x, {tan(36)*0.5*\l});
% y = tan(108)x + ((tan(144)*(tan(36)*0.25*(1+sqrt(5))*\l - tan(252)*0.25*(1+sqrt(5))*\l + tan(144)*\l)/(tan(144) - tan(252)) - tan(144)*\l) - tan(108)*(tan(36)*0.25*(1+sqrt(5))*\l - tan(252)*0.25*(1+sqrt(5))*\l + tan(144)*\l)/(tan(144) - tan(252)))
\pgfmathsetmacro{\m}{tan(108)}
\pgfmathsetmacro{\b}{((tan(144)*(tan(36)*0.25*(1+sqrt(5))*\l - tan(252)*0.25*(1+sqrt(5))*\l + tan(144)*\l)/(tan(144) - tan(252)) - tan(144)*\l) - tan(108)*(tan(36)*0.25*(1+sqrt(5))*\l - tan(252)*0.25*(1+sqrt(5))*\l + tan(144)*\l)/(tan(144) - tan(252)))}
\pgfmathsetmacro{\p}{(tan(36)*0.5*\l - \b)/\m}
\pgfmathsetmacro{\q}{(-\b - tan(144)*\l)/(\m - tan(144))}
\draw[line width=0.1mm, domain={\p}:{\q}] plot(\x, {\m*\x + \b});
\end{tikzpicture}
“有点”混乱,但确实有效。因此,问题在于将具有正确参数的螺旋放在正确的位置。
我计算了原始图像中两条红线的交点(螺旋的极点)的坐标,基长为 40,并移动了旋转的螺旋:
\pgfmathsetmacro{\cx}{(-sqrt(0.5*(5+sqrt(5)))*20 - (1/3)*sqrt(5+2*sqrt(5))*40)/(((-1/3)*sqrt(5+2*sqrt(5)) - sqrt(0.5*(5+sqrt(5)))))}
\pgfmathsetmacro{\cy}{(-1/3)*sqrt(5+2*sqrt(5))*((-sqrt(0.5*(5+sqrt(5)))*20 - (1/3)*sqrt(5+2*sqrt(5))*40)/(((-1/3)*sqrt(5+2*sqrt(5)) - sqrt(0.5*(5+sqrt(5)))))) + (1/3)*sqrt(5+2*sqrt(5))*40}
\pgfmathsetmacro{\a}{(5/(3*pi))*ln((1+sqrt(5))/2)}
\begin{scope}[rotate around={-270:(\cx, \cy)}]
\draw[line cap=round, line width=0.2mm, domain=-3*pi:4*pi, variable=\t, samples=1000]
plot ({\cx + 2.04666*exp(\a*\t)*cos(deg(\t))},
{\cy - 2.04666*exp(\a*\t)*sin(deg(\t))});
\end{scope}
输出看起来不错,但估计参数 2.04666 让我很烦恼。有什么方法可以计算它吗?有没有更好的方法将正确的螺旋放在正确的位置?
答案1
我把螺旋画反了,我想这是错误的做法。
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc,intersections,math}
\begin{document}
\begin{tikzpicture}[line join=round, line cap=round, x=1pt, y=1pt]
\tikzmath{%
coordinate \a, \b, \c, \o;
int \i;
\g = (1 + sqrt(5)) / 2;
\a = (0,0);
\b = (100,0);
for \i in {1,...,6}{
if (\i > 1) then {
\a = (\b);
\b = ($(\b)!1-1/\g!(\c)$);
};
\n = veclen(\bx-\ax, \by-\ay) * \g;
\c = ($(\b)!\g!-72:(\a)$);
{
\fill [draw=black!50, fill opacity=1/10]
(\a) coordinate (a-\i) --
(\b) coordinate (b-\i) --
(\c) coordinate (c-\i) -- cycle;
};
};
}
\draw [red, dashed, name path=A] ($(a-1)!0.5!(c-1)$) -- (b-1);
\draw [red, dashed, name path=B] ($(a-2)!0.5!(c-2)$) -- (b-2);
\path [name intersections={of=A and B, by=O}];
\tikzmath{%
\c1 = (c-1);
\c2 = (c-2);
\o = (O);
\r1 = veclen(\cx1-\ox, \cy1-\oy);
\r2 = veclen(\cx2-\ox, \cy2-\oy);
\th1 = Mod(atan2(\cy1-\oy, \cx1-\ox), 360);
\th2 = Mod(atan2(\cy2-\oy, \cx2-\ox), 360);
\ph = \th2 > \th1 ? \th2 - \th1 : \th1 - \th2;
\k = ln(1/\g)/\ph;
\n = 20 * \ph;
}
\draw [blue!50!cyan, shift=(O)]
plot [smooth, domain=0:\n, samples=200, variable=\t]
(\th1+\t:{\r1*exp(\k*\t)});
\end{tikzpicture}
\end{document}
答案2
一个代码高尔夫解决方案;)
\documentclass[tikz,border=7mm]{standalone}
\def~{(36:1)--(0,0)--(1,0)edge[bend left=54,blue](0,0)
[shift={(1,0)},rotate=108,scale=0.61803398875]}
\begin{document}
\tikz[scale=4]\draw~~~~~~;
\end{document}
编辑:arc
代替的“更好”的近似值edge
是:
\documentclass[tikz,border=7mm]{standalone}
\def~{(0,0)edge[black](36:1)edge[black](1,0)arc(-144:-36:0.61803398875)
[shift={(1,0)},rotate=108,scale=0.61803398875]}
\begin{document}
\tikz[blue,scale=3]\draw~~~~~~;
\end{document}
在这种情况下,“精确”螺旋可以用以下方式绘制:
\draw[red,shift={(0.675186453011,0.333224435406)}]
plot[domain=-pi:3*pi,samples=300] (\x r:{0.379556295255/exp(0.255290802108*\x)});
如果我们将其叠加,我们就可以看到近似误差。