根据问题螺旋问题,我希望能够在这些的末尾、开头或结尾添加一个箭头,我怎样才能以最简单的方式做到这一点?
其中一个答案代码如下,如何在螺旋的末尾或开头添加箭头?
\documentclass{book}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tikzset{helix part/.style n args={2}{insert path={
plot[smooth,variable=\x,domain=-90+#1*180:90+#1*180,
samples=11] ({\pgfkeysvalueof{/tikz/helix/radius}*cos(\x)},
{\x*(\pgfkeysvalueof{/tikz/helix/stretch}*\pgfkeysvalueof{/tikz/helix/radius}/360)+#2},{-\pgfkeysvalueof{/tikz/helix/radius}*sin(\x)})
-- plot[smooth,variable=\x,domain=90+#1*180:-90+#1*180,
samples=11]
({\pgfkeysvalueof{/tikz/helix/radius}*cos(\x)},
{\x*(\pgfkeysvalueof{/tikz/helix/stretch}*\pgfkeysvalueof{/tikz/helix/radius}/360)+\pgfkeysvalueof{/tikz/helix/width}+#2},{-\pgfkeysvalueof{/tikz/helix/radius}*sin(\x)})
}},helix/.is family,
helix/.cd,
radius/.initial=3,stretch/.initial=3,width/.initial=1.5}
\tdplotsetmaincoords{90}{105}
\newcommand{\myprotein}[2][]{%
\begin{scope}[tdplot_main_coords,scale=.1,#1]
rectangle (20,1.1*\pgfkeysvalueof{/tikz/helix/radius});
\foreach \X in {0,2,...,8}
{
\path[top color=#2!60!black,bottom color=#2!30,middle color=#2,
helix part={\X}{0}];
}
\foreach \X in {1,3,...,9}
{
\path[top color=#2!30,bottom color=#2!60!black,middle color=#2,
helix part={\X}{0}];
}
\end{scope}}
\begin{tikzpicture}
\fill (0,0) ellipse (2 and 1);
\myprotein{olive}
\end{tikzpicture}
\end{document}
这张手工制作的图片可以帮忙吗?
答案1
更新:
经过小幅修改,我用正弦函数替换了控件的使用,看起来更好,厚度和宽度的控制也是如此,对于曲线,当的值设置为时,会发生错误,Coil2=1
它仅适用于逆时针曲线;如果coil2=-1
设置为,则仅适用于小时曲线,这是因为无法从后续制作中获得节点。
结果:
U-MWE:
\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{decorations.markings,calc}
\begin{document}
%from https://tex.stackexchange.com/a/449744/154390
\begin{tikzpicture}[
CoilColor/.store in=\coilcolor,CoilColor=black,
Steps/.store in=\Steps,Steps=0.1,
Thickness/.store in=\Thickness,Thickness=4pt,
W/.store in=\W,W=5mm,
Coil2/.style={
draw=none,
postaction={
decorate,
decoration={
markings,
mark= between positions 0 and 1 step \Steps
with {
\begin{scope}[yscale=#1]
\pgfmathparse{int(\pgfdecoratedpathlength/28.45*100*\Steps)}
\edef\H{\pgfmathresult/100}
\ifnum\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}=1
\shade[inner color=\coilcolor,outer color=\coilcolor!50!black]
(0,0)
sin (\H/4,\W/2) coordinate (b)
-- ++(\Thickness,0)
cos ++(-\H/4,-\W/2)
-- (0,0);
\fi
\ifnum\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}>1
\coordinate (b) at (d);
\fi
\path (b)
cos ++(\H/4,-\W/2)
sin ++(\H/4,-\W/2) coordinate (a)
-- ++(\Thickness,0)
cos ++(-\H/4,\W/2)
sin ++(-\H/4,\W/2)
-- (b);
\path (b)++(\H,0)coordinate (d);
\shade[inner color=\coilcolor,outer color=\coilcolor!50!black]
(a)
cos ++(\H/4,\W/2)
sin ++(\H/4,\W/2)
-- ++(\Thickness,0)
cos ++(-\H/4,-\W/2)
sin ++(-\H/4,-\W/2)
-- (a);
\shade[outer color=\coilcolor!50!white,inner color=\coilcolor]
(b)
cos ++(\H/4,-\W/2)
sin ++(\H/4,-\W/2)
-- ++(\Thickness,0)
cos ++(-\H/4,\W/2)
sin ++(-\H/4,\W/2)
-- (b);
\end{scope}
}
}
},
postaction={
decorate,
decoration={
markings,
mark=at position 1
with {
\begin{scope}[yscale=#1]
\pgfmathparse{int(\pgfdecoratedpathlength/28.45*100*\Steps)}
\edef\H{\pgfmathresult/100}
\shade[outer color=\coilcolor!50!white,inner color=\coilcolor]
(d)
cos ++(\H/4,-\W/2) coordinate (temp)
-- ++(-\Thickness/2,0)
-- ++(\Thickness/2+\Thickness*0.7,-\Thickness*2)
-- ($(temp)+(\Thickness+\Thickness/2,0)$)
--($(temp)+(\Thickness,0)$)
sin ++(-\H/4,\W/2)
-- (d);
\end{scope}
}
}
}
}
]
\draw[Coil2=1,CoilColor=yellow,Steps=1,Thickness=3mm,W=1.5cm] (0,0) -- ++ (1cm,0);
\draw[Coil2=-1,CoilColor=yellow,Steps=1,Thickness=3mm,W=1.5cm] (6cm,0) -- ++ (-1cm,0);
\draw[Coil2=-1,CoilColor=red,Steps=0.5,Curvature=0.1,Thickness=1mm] (0,-4.5cm) -- ++ (0,20mm);
\draw[Coil2=-1,CoilColor=magenta,Steps=0.25] (0.7,-4.5cm) -- ++(2,1.5);
\draw[Coil2=1,CoilColor=green!50!cyan,Steps=0.05,Thickness=1.5mm,W=0.5cm]
(2,-4.5cm)++(1,0)
to[in=-90,out=00]++(30mm,15mm)
to[in=0,out=90]++(-30mm,15mm)
to[in=-135,out=180]++(-20mm,-10mm)
-- ++ (-2mm,-2mm);
\end{tikzpicture}
\end{document}
先前的尝试
这是我曾经在关于线圈的帖子,我在末尾添加了箭头,尽管它并不相同,因为我必须修改更多的东西,但边缘很薄,因此它们可以在曲线中使用,它们可以用于制作蛋白质图形,然后我可能有时间测试是否可以按照你的建议去做。
结果:
梅威瑟:
\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
%from https://tex.stackexchange.com/a/449744/154390
\begin{tikzpicture}[
CoilColor/.store in=\coilcolor,CoilColor=black,
S/.store in=\S,S=0.1,
W/.store in=\W,W=0.4,
Coil2/.style={
draw=none,
postaction={
decorate,
decoration={
markings,
mark= between positions 0 and 1 step \S
with {
\begin{scope}[yscale=#1]
\pgfmathparse{int(\pgfdecoratedpathlength/28.45*100*\S)}
\edef\Hight{\pgfmathresult}
\ifnum\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}=1
\path (0,0)++(90: \Hight/200 and \W) coordinate (b);
\fi
\ifnum\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}>1
\coordinate (b) at (d);
\fi
\path (b) arc (90:-135: \Hight/200 and \W) coordinate (a);
\path (b) arc (90:-45: \Hight/200 and \W) coordinate (c);
\path (b)++(\Hight/100,0) coordinate (d);
\draw[fill,\coilcolor!70!black]
(c)
.. controls +(-0.175,0) and +(-0.275,0) .. (d)
.. controls +(-0.325,0) and +(-0.225,0) .. (c);
\draw[white,line width=2pt]
(b)
.. controls +(0.3,0) and +(0.2,0) .. (c);
\draw[fill,\coilcolor]
(b)
.. controls +(0.275,0) and +(0.175,0) .. (c)
.. controls +(0.225,0) and +(0.325,0) .. (b);
\end{scope}
}
}
},
postaction={
decorate,
decoration={
markings,
mark=at position 0.99
with {
\begin{scope}[yscale=#1]
\pgfmathparse{int(\pgfdecoratedpathlength/28.45*100*\S)}
\edef\Hi{\pgfmathresult}
\draw[fill,\coilcolor!70!black]
(d)
.. controls +(0.2,0) and +(0,0) .. ++(\Hi/150,-\W)
-- ++(2pt,-0.5pt)
-- ++(-4pt,-6pt)
-- ++(-2pt,7.5pt)
-- ++(2pt,-0.8pt).. controls +(0,0) and +(0.2,0) ..(d);
\end{scope}
}
}
}
}
]
\draw[Coil2=-1,CoilColor=red,S=0.2] (0,0) -- ++ (0,2);
\draw[Coil2=1,CoilColor=orange,S=0.2] (0.7,2) -- ++ (2,0);
\draw[Coil2=-1,CoilColor=magenta,S=0.2] (0.7,-0.5) -- ++(2,1.5);
\draw[Coil2=-1,CoilColor=green!50!cyan,S=0.12,draw] (3,0) to[in=180,out=00] ++(3,1.5);
\end{tikzpicture}
\end{document}