我在将单个非线性变换应用于用自定义图片装饰的路径时遇到了问题。下面是一个最小示例:
\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes}
\usepgflibrary{curvilinear}
\usepgfmodule{nonlineartransformations}
\begin{document}
\tikzset{
cell/.pic={
% Shading for the endothelial cells
\pgfdeclareradialshading{centred}{\pgfqpoint{0bp}{0bp}}{%
color(0bp)=(white);
color(10bp)=(red!10!white);
color(20bp)=(red!20!white);
color(30bp)=(red!30!white);
color(100bp)=(red)
}
\node[%
draw,
rounded rectangle,
inner xsep=0.24cm,
inner ysep=0.075cm,
shade,
shading=centred,
ultra thin
] at (0,0) {};
}
}
\begin{tikzpicture}
\def\wallSideStartX{0}
\def\wallSideLength{15cm}
\coordinate (origin) at (\wallSideStartX,0);
\def\thickness{1.50cm}
% Start nonlinear transformation
\pgfsetcurvilinearbeziercurve
{\pgfpointxy{0}{0}}{\pgfpointxy{10}{0}}
{\pgfpointxy{20}{5}}{\pgfpointxy{20}{15}}
\pgftransformnonlinear{\pgfgetlastxy\x\y%
\pgfpointcurvilinearbezierorthogonal{\x}{\y}}%
\draw[%
fill=red
] (origin)
rectangle
++(\wallSideLength,\thickness);
\path[%
postaction=decorate,
decoration={%
markings,
mark=between positions 0 and 1 step 5mm with{%
\pic[%
%scale=0.7,
sloped,
transform shape
] {cell};
}
}
] (\wallSideStartX,0.5*\thickness)
--
++(\wallSideLength,0);
\end{tikzpicture}
\end{document}
相同的变换以某种方式影响装饰和其下的实际路径。理想情况下,我希望装饰也跟随矩形。
我对 TikZ 中的非线性变换不是很有经验,所以我猜想这可能是它与图片和装饰路径之间的一些交互,而这些交互我并不了解,到目前为止,我找不到任何可以解决它的方法。有人能帮我解决这个问题吗?非常感谢!
答案1
我建议用以下方法解决您的问题:我已将内皮细胞图像沿路径定位。如果链条放置不正确,请调整位置。
\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepgflibrary{curvilinear}
\usepgfmodule{nonlineartransformations}
\begin{document}
\tikzset{
cell/.pic={
% Shading for the endothelial cells
\pgfdeclareradialshading{centred}{\pgfqpoint{0bp}{0bp}}{%
color(0bp)=(white);
color(10bp)=(red!10!white);
color(20bp)=(red!20!white);
color(30bp)=(red!30!white);
color(100bp)=(red)
}
\node[%
draw,
rounded rectangle,
inner xsep=0.24cm,
inner ysep=0.075cm,
shade,
shading=centred,
ultra thin
] at (0,0) {};
}
}
\begin{tikzpicture}
\def\wallSideStartX{0}
\def\wallSideLength{15}
\coordinate (origin) at (\wallSideStartX,0);
\def\thickness{1.5}
% Start nonlinear transformation
\pgfsetcurvilinearbeziercurve
{\pgfpointxy{0}{0}}{\pgfpointxy{10}{0}}
{\pgfpointxy{20}{5}}{\pgfpointxy{20}{15}}
\pgftransformnonlinear{\pgfgetlastxy\x\y%
\pgfpointcurvilinearbezierorthogonal{\x}{\y}}%
\draw[%
fill=red
] (origin)
rectangle
++(\wallSideLength,\thickness);
% added: chain of endothelial cells
% space at the beginning: .033
\foreach \i in {.02,.053,...,.683} {
\path (\wallSideStartX,.5*\thickness)
-- pic[pos=\i] {cell}
++(\wallSideLength,0);
}
% space at the end: .03
\foreach \i in {.71,.74,...,1} {
\path (\wallSideStartX,.5*\thickness)
-- pic[pos=\i] {cell}
++(\wallSideLength,0);
}
\end{tikzpicture}
\end{document}
编辑:我尝试沿途倾斜细胞。这是否符合您的需求,或者内皮细胞的形状不正确但对您来说(非常)重要?像以前一样,使用单个参数进行操作。
\documentclass[margin=5pt,tikz]{standalone}
\usepgflibrary{curvilinear}
\usepgfmodule{nonlineartransformations}
\begin{document}
\begin{tikzpicture}[
cellRectangle/.pic={
% The option 'rounded corners' does not work, because the geometric figure is too small!
\draw[%
outer color=red!30!white,
inner color=white,
ultra thin] (0,0)
rectangle
(.5,.15);
}
]
\newcommand\wallSideStartX{0}
\newcommand\wallSideLength{15}
\newcommand\thickness{1.5}
\coordinate (origin) at (\wallSideStartX,0);
% Start nonlinear transformation
\pgfsetcurvilinearbeziercurve
{\pgfpointxy{0}{0}}{\pgfpointxy{10}{0}}
{\pgfpointxy{20}{5}}{\pgfpointxy{20}{15}}
\pgftransformnonlinear{\pgfgetlastxy\x\y%
\pgfpointcurvilinearbezierorthogonal{\x}{\y}}%
\draw[%
left color=red!70,
right color=red!80,
] (origin)
rectangle
++(\wallSideLength,\thickness);
% endothelial cells
\foreach \i in {0.01,.046,...,.97} {
\path (\wallSideStartX,.425*\thickness)
-- pic[pos=\i] {cellRectangle}
++(\wallSideLength,0);
}
\end{tikzpicture}
\begin{tikzpicture}[
cellEllipse/.pic={
\draw[%
outer color=red!30!white,
inner color=white,
ultra thin] (0,0)
ellipse
(.25cm and .14cm);
}
]
\newcommand\wallSideStartX{0}
\newcommand\wallSideLength{15}
\newcommand\thickness{1.5}
\coordinate (origin) at (\wallSideStartX,0);
% Start nonlinear transformation
\pgfsetcurvilinearbeziercurve
{\pgfpointxy{0}{0}}{\pgfpointxy{10}{0}}
{\pgfpointxy{20}{5}}{\pgfpointxy{20}{15}}
\pgftransformnonlinear{\pgfgetlastxy\x\y%
\pgfpointcurvilinearbezierorthogonal{\x}{\y}}%
\draw[%
left color=red!70,
right color=red!80,
] (origin)
rectangle
++(\wallSideLength,\thickness);
% endothelial cells
\foreach \i in {.025,.06,...,.99} {
\path (\wallSideStartX,.5*\thickness)
-- pic[pos=\i] {cellEllipse}
++(\wallSideLength,0);
}
\end{tikzpicture}
\end{document}