我正在尝试使用非常酷的 tikzducks.sty 画一只睡觉的鸭子。我遇到了两个问题。为了解释它们,让我先介绍一下 MWE。
\documentclass{standalone}
\usepackage{tikzducks}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[scale=9] % changing the scale to 1 (or even somewhat larger values) fails
\duck[eye=yellow!50!brown,pupil=yellow!50!brown]
\begin{scope}[ultra thick,rotate=-20,decoration={ticks,raise=-4,amplitude=4,segment length=8
}]
\draw[decorate] (0.161,1.682) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
% \draw[decorate] (0.23,1.7675) ellipse (0.0893 and 0.125); %from tikzducks.sty
\draw[decorate] (-0.06,1.74) ellipse (0.0786 and 0.1143); %from tikzducks.sty
% \draw[decorate] (-0.125,1.67) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
\end{scope}
\end{tikzpicture}
\end{document}
右眼(好吧,鸭子会说是她的左眼)大致就是我想要的样子。但是,我必须根据 tikzducks.sty 中的值移动我绘制的圆弧的椭圆中心。在左侧,我绘制了完整的椭圆,无需调整坐标。(当然,最终我也只想要一个圆弧。)所以我的第一个问题是,是否可以在不调整此坐标的情况下在椭圆上绘制椭圆弧。
更糟糕的是,如果我缩小图片,即删除[scale=9]
后面的部分begin{tikzpicture}
,编译就会失败并出现错误! Dimension too large.
。有办法解决这个问题吗?(或者鸭子必须一直保持清醒?;-)
答案1
我不会使用装饰。你会在不同比例下遇到问题,而且你无法真正微调长度。我会一根一根地画睫毛,甚至可能弯曲一些。由于线宽不会缩放,因此需要某种样式来适应睫毛。睡眠面膜可能更容易 ;-)。
\documentclass{article}
\usepackage{tikzducks}
\begin{document}
\begin{tikzpicture}[scale=1]
\duck
\path[rotate=-20]
(0.23,1.7675)coordinate(ECR) ellipse (0.0893 and 0.125);
\path[rotate=-20]
(-0.06,1.74)coordinate(ECL) ellipse (0.0786 and 0.1143);
\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECR)--++(\x*15+220:0.11cm+\y*0.012cm); };
\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECL)--++(\x*15+220:0.11cm+\y*0.009cm); };
%
%
\fill[rotate=-20,yellow!50!brown]
(0.23,1.7675) ellipse (0.0893 and 0.125);
%
\fill[rotate=-20,yellow!50!brown]
(-0.06,1.74) ellipse (0.0786 and 0.1143);
\end{tikzpicture}
\begin{tikzpicture}[scale=5] % changing the scale to 1 (or even somewhat larger values) fails
\duck
\path[rotate=-20]
(0.23,1.7675)coordinate(ECR) ellipse (0.0893 and 0.125);
\path[rotate=-20]
(-0.06,1.74)coordinate(ECL) ellipse (0.0786 and 0.1143);
\begin{scope}[ultra thick]
\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECR)--++(\x*15+220:0.11cm+\y*0.012cm); };
\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECL)--++(\x*15+220:0.11cm+\y*0.009cm); };
\end{scope}
%
%
\fill[rotate=-20,yellow!50!brown]
(0.23,1.7675) ellipse (0.0893 and 0.125);
%
\fill[rotate=-20,yellow!50!brown]
(-0.06,1.74) ellipse (0.0786 and 0.1143);
\end{tikzpicture}
\end{document}
答案2
使用 veclen 的更新版本的解决方案。我使用了 xfp。问题与我的宏相同\tkzMarkAngle
。我使用了库装饰并且小角度值出现错误。
\documentclass{standalone}
\usepackage{tikzducks,xfp}
\usetikzlibrary{decorations.pathreplacing}
\makeatletter
\let\pgfmath@function@veclen\relax
\pgfmathdeclarefunction*{veclen}{2}{%
\begingroup%
\pgfmath@x#1pt\relax%
\pgfmath@y#2pt\relax%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
\edef\tkz@temp@a{\fpeval{\pgfmath@tonumber{\pgf@xa}}}
\edef\tkz@temp@b{\fpeval{\pgfmath@tonumber{\pgf@ya}}}
\edef\tkz@temp@sum{\fpeval{%
(\tkz@temp@a*\tkz@temp@a+\tkz@temp@b*\tkz@temp@b)}}
\edef\tkz@xfpMathLen{\fpeval{sqrt(\tkz@temp@sum)}}
%\edef\pgfmath@tmp{\fpeval{round(\tkzFPMathLen,6)}}
%\pgfmath@tmp %
\pgfmath@returnone\tkz@xfpMathLen pt%
\endgroup%
}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=1] % changing the scale to 1 (or even somewhat larger values) fails
\duck[eye=yellow!50!brown,pupil=yellow!50!brown]
\begin{scope}[line width=.4pt,rotate=-20,decoration={ticks,raise=-.5,amplitude=.5,segment length=1.5
}]
\draw[decorate] (0.161,1.682) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
\draw[decorate] (-0.125,1.67) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
\end{scope}
\end{tikzpicture}
\end{document}