例如,如何从给定的中心线绘制一条梁(或更奇特的形状)?这就是我的意思,但解决方案不太好。我想添加图案等。
\documentclass[12pt,tikz,border=5pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
% grid to see the coordinates
% Point A with circle and label
\coordinate [label={[label distance=3mm]below:A}] (A) at (1,3);
% Point B with circle and label
\coordinate [label={[label distance=3mm]right:B}](B) at (6,6);
% Point C with circle and label
\coordinate [label={[label distance=3mm]below:C}](C) at (7,4);
% Point D with circle and label
\coordinate [label={[label distance=3mm]right:D}](D) at (9,4);
\draw (D) circle [radius=3pt];
\draw[line width=20pt,line cap=round] (A) -- (B) -- (C) -- (D);
\draw[line width=14pt,white,line cap=round] (A) -- (B) -- (C) -- (D);
\draw (A) -- (B) -- (C) -- (D);
% grid to see the coordinates
\draw[help lines, step=1] (0,0) grid (10,8);
\draw (A) circle [radius=3pt];
\draw (B) circle [radius=3pt];
\draw (C) circle [radius=3pt];
\draw (D) circle [radius=3pt];
\end{tikzpicture}
\end{document}
答案1
你可以适应我之前的回答像这样:
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}
\tikzset{
rect/.style= { to path={ let \n1={sqrt(2)*#1},
\p1=($(\tikztostart)!\n1!-135:(\tikztotarget)$), \p2=($(\tikztostart)!\n1!135:(\tikztotarget)$),
\p3=($(\tikztotarget)!\n1!-135:(\tikztostart)$), \p4=($(\tikztotarget)!\n1!135:(\tikztostart)$)
in (\p1) -- (\p2) -- (\p3) -- (\p4) --cycle (\tikztotarget)}
},
round/.style={rounded corners=#1,rect/.default=#1}
}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (7,5);
\def\mypath{(1,2) foreach \a in {30,-45,0,90} {to[rect] ++(\a:2)}}
\fill[round=4mm,black] \mypath;
\shade[round=3mm,left color=red, right color=blue] \mypath;
\pattern[round=3mm,pattern color=white,pattern=bricks] \mypath;
\end{tikzpicture}
\end{document}
答案2
使用pgf-blur
。文档说阴影总是黑色的。但要找出那个黑色,并用我们的\blurcolor
\documentclass[tikz]{standalone}
\usetikzlibrary{shadows.blur}
\makeatletter
\tikzset{
/tikz/render blur shadow/.code={
\pgfbs@savebb
\pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
\pgfbs@compute@shadow@bbox
\pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
\pgfbs@apply@canvas@transform
\colorlet{pstb@shadow@color}{white!\pgfbs@opacity!black}%
\pgfdeclarefading{shadowfading}{\pgfbs@paint@fading}%
\pgfsetfillcolor{\blurcolor}%
\pgfsetfading{shadowfading}%
{\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
\pgfbs@usebbox{fill}%
\pgfbs@restorebb
}
}
\begin{document}
\begin{tikzpicture}
\fill[black](0,2)rectangle(10,7);
\def\blurcolor{yellow}
\path[blur shadow,shadow xshift=0,shadow yshift=0,
shadow blur radius=20pt,shadow opacity=100,shadow blur steps=100]
(1,3)--(6,6)--cycle(6,6)--(7,4)--cycle(7,4)--(9,4)--cycle;
\end{tikzpicture}
\end{document}