我有由 3 个点创建的虚线,但我希望曲线上的点密度不断增加。我设法创建了一个点图案,但间距是固定的。一般情况下,我没有曲线方程。
是否可以使用 tikz 直接控制曲线上点的密度?也许有一个功能?
\documentclass[8pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\usepgfplotslibrary{fillbetween}
% Dot pattern
\tikzset{
dot diameter/.store in=\dot@diameter,
dot diameter=2pt,
dot spacing/.store in=\dot@spacing,
dot spacing=3pt,
dots/.style={
line width=\dot@diameter,
line cap=round,
dash pattern=on 0pt off \dot@spacing
}
}
\begin{document}
\begin{tikzpicture}
\coordinate (z) at (0.9,-1);
% Dots along a curve
\draw[draw=black,dots] plot [smooth,tension=1] coordinates { ($(z)+(-0.5,-1)$) ($(z)+(0.1,-0.5)$) ($(0,0)$) };
\end{tikzpicture}
\end{document}
谢谢 !
答案1
是的,可以这样做。下面有两个选项:要么将位置传递给列表,要么为间距定义一个函数。第二个选项的语法是
variable dots={<function>}{<samples>}
例如
variable dots={2*\x/(10+\x)}{1,...,7}
其中,默认情况下,函数是 的函数\x
。代码已注释。dimension too large
使用 还可以避免错误fpu
。
\documentclass[8pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings,fpu}
\tikzset{dot diameter/.initial=2pt,
add marking position/.code={\edef\x{#1}%
\pgfmathparse{spacingfunction(\x)}%
\ifx\mymarkpositions\empty
\edef\mymarkpositions{\pgfmathresult}
\else
\edef\mymarkpositions{\mymarkpositions,\pgfmathresult}%
\fi},variable dots/.code 2 args={%
\tikzset{declare function={spacingfunction(\x)=#1;}}%
\let\mymarkpositions\empty%
\tikzset{add marking position/.list={#2}}%
%\typeout{\mymarkpositions}
\tikzset{postaction={decorate,decoration={markings,%
my mark/.list/.expanded={\mymarkpositions}}}}}}
\tikzset{/pgf/decoration/my mark/.code=\tikzset{/pgf/decoration/mark={at position #1 with
{\fill circle[radius=\pgfkeysvalueof{/tikz/dot diameter}];}}}}
\begin{document}
\begin{tikzpicture}
\coordinate (z) at (0.9,-1);
% Dots along a curve
\draw[/pgf/fpu/install only={reciprocal},%<- only to avoid "dimension too large" errors
draw=black,postaction={decorate,decoration={markings,
my mark/.list={0.18181,0.33333,0.46153,0.57143,0.66666,0.75,0.82352}%<- explicit list
}}]
plot [smooth,tension=1] coordinates
{ ($(z)+(-0.5,-1)$) ($(z)+(0.1,-0.5)$) ($(0,0)$) };
\end{tikzpicture}
\begin{tikzpicture}
\coordinate (z) at (0.9,-1);
% Dots along a curve
\draw[/pgf/fpu/install only={reciprocal},%<- only to avoid "dimension too large" errors
draw=black,variable dots={2*\x/(10+\x)}%<- function
{1,...,7}]%<- arguments
plot [smooth,tension=1] coordinates
{ ($(z)+(-0.5,-1)$) ($(z)+(0.1,-0.5)$) ($(0,0)$) };
\end{tikzpicture}
\end{document}