本着这个问题,如何使用新的arrows.meta
TikZ 库制作自定义箭头尖?我想制作一个半圆形的尖头,open
理想情况下,它可以接受选项,也许还有其他选项,例如长度(或半径或圆形箭头尖接受的任何选项)。
答案1
声明新箭头的文档相当全面,但示例中似乎存在一些错误。我不是这方面的专家,arrows.meta
但以下似乎是开始的最低要求:
\documentclass[tikz,border=0.25cm]{standalone}
\usetikzlibrary{arrows.meta}
\makeatletter
\pgfdeclarearrow{
name=semicircle,
parameters={
\the\pgfarrowlength,%
\ifpgfarrowopen o\fi%
},
setup code={
% The line end value:
\pgfarrowssettipend{0pt}
\pgf@x=-.25\pgfarrowlength
\advance\pgf@x by-.5\pgflinewidth
% The hull point:
\pgfutil@tempdima=0.25\pgfarrowlength
\advance\pgfutil@tempdima by.5\pgflinewidth
\pgfarrowssetlineend{\pgf@x}
\pgfarrowssetvisualbackend{-.25\pgfarrowlength}
\pgfarrowssetbackend{-.75\pgfarrowlength}
\pgfarrowssavethe\pgfarrowlength
\pgfarrowlinewidth=\pgflinewidth
\pgfarrowssavethe\pgfarrowlinewidth
\pgfarrowshullpoint{0pt}{0pt}
\pgfarrowshullpoint{0pt}{-\pgfutil@tempdima}
\pgfarrowshullpoint{0pt}{\pgfutil@tempdima}
},
drawing code={
\pgfpathmoveto{\pgfpoint{-.25\pgfarrowlength-.5\pgflinewidth}{.25\pgfarrowlength}}
\pgfpathlineto{\pgfpoint{-.25\pgfarrowlength-.5\pgflinewidth}{-.25\pgfarrowlength}}
\pgfpatharc{-90}{90}{0.25\pgfarrowlength}
\pgfpathclose
\ifpgfarrowopen\pgfusepathqstroke\else\ifdim\pgfarrowlinewidth>0pt\pgfusepathqfillstroke\else\pgfusepathqfill\fi\fi
},
defaults={ length=10pt }
}
\begin{document}
\begin{tikzpicture}
\draw [help lines] grid (3,2);
\draw [semicircle-{semicircle[open]}] (0,0) -- (3,2);
\draw [very thick, {semicircle[length=40pt,open]}-{semicircle[length=20pt]}]
(0,2) -- (3,0);
\end{tikzpicture}
\end{document}
答案2
我对马克的答案做了一些改进,以便半圆与圆完全一致。
\pgfdeclarearrow{
name=semicircle,
defaults={
length = +2.39365pt +3.191538,
line width = +0pt 1 1,
},
setup code={
% Cap the line width at 1/2th of the length
\[email protected]\pgfarrowlength
\ifdim\pgf@x<\pgfarrowlinewidth
\pgfarrowlinewidth\pgf@x
\fi
\[email protected]\pgfarrowlength\advance\pgfutil@tempdima by-.5\pgfarrowlinewidth
\[email protected]\pgfarrowlength\advance\pgfutil@tempdimb by.5\pgfarrowlinewidth
\ifpgfarrowreversed
\pgfarrowssetlineend{.5\pgfarrowlength\advance\pgf@x by-.5\pgfarrowlinewidth}
\else
\pgfarrowssetlineend{.5\pgfarrowlinewidth}
\fi
\pgfarrowssettipend{\pgfutil@tempdimb}
% The hull:
\pgfarrowsupperhullpoint{0pt}{.5\pgfarrowlength}
\pgfarrowsupperhullpoint{0.20710678118\pgfarrowlength}{.5\pgfarrowlength}
\pgfarrowsupperhullpoint{0.5\pgfarrowlength}{0.20710678118\pgfarrowlength}
% The following are needed in the code:
\pgfarrowssavethe\pgfarrowlinewidth
\pgfarrowssavethe\pgfarrowlength
\pgfarrowssavethe\pgfutil@tempdima
\pgfarrowssavethe\pgfutil@tempdimb
},
drawing code = {
\pgfsetdash{}{+0pt}
\ifpgfarrowroundjoin\pgfsetroundjoin\else\pgfsetmiterjoin\fi
\ifdim\pgfarrowlinewidth=\pgflinewidth\else\pgfsetlinewidth{+\pgfarrowlinewidth}\fi
\pgfpathmoveto{\pgfpoint{.5\pgfarrowlinewidth}{\pgfutil@tempdima}}
\pgfpathlineto{\pgfpoint{.5\pgfarrowlinewidth}{-\pgfutil@tempdima}}
\pgfpatharc{-90}{90}{\pgfutil@tempdima}
\pgfpathclose
\ifpgfarrowopen\pgfusepathqstroke\else\ifdim\pgfarrowlinewidth>0pt\pgfusepathqfillstroke\else\pgfusepathqfill\fi\fi
},
parameters = {
\the\pgfarrowlinewidth,%
\the\pgfarrowlength,%
\ifpgfarrowopen o\fi%
\ifpgfarrowroundjoin j\fi%
},
}