是否可以将阴影应用于与其当前切线垂直的路径。
我想绘制某种 3d 管道。我的问题与这个问题。我想画 3d 分子,但不知道怎样画出原子之间的键。
我想要一些类似的东西
\draw[bond color=red; bond width=15pt] (atom1) -- (atom2);
结果应为从坐标atom1
到坐标 的极点。极点表示一个矩形,其长度为和atom2
之间的距离,高度为 15pt,沿高度轴填充红白红色调。atom1
atom2
我实际上可以使用和来做到这一点\shade
,shading angle
但随后我必须根据atom1
和的坐标自己计算阴影角度atom2
。
对此有什么建议吗?
谢谢
答案1
理想情况下,可以使用专用的装饰(类似于库提供的用于连接概念的装饰mindmap
),但这里有一个使用show path construction
装饰的简单示例。
手动应用阴影是为了(a)说明如何完成(b)绕过将阴影剪切到中心四分之一的默认过程。
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\colorlet{bar.top}{red}
\colorlet{bar.bottom}{blue}
\pgfdeclareverticalshading[bar.top,bar.bottom]{shaded.bar}{100bp}{
color(0bp)=(bar.bottom);color(100bp)=(bar.top)}
\tikzset{shading bar/.style args={#1 thick from #2 to #3}{
decoration={show path construction,
lineto code={
\pgfscope%
%
% Set the colors.
\colorlet{bar.top}{#2}%
\colorlet{bar.bottom}{#3}%
%
% Manually apply the shading.
% As the bar is a rectangle, scale the shading (which is 100bp x 100bp).
% Other bar shapes would other adjustments before applying the shading.
\pgftransformshift{\pgfpointdecoratedinputsegmentfirst}%
\pgftransformrotate{\pgfdecoratedangle}%
\pgftransformxscale{\pgfdecoratedinputsegmentlength/100bp}%
\pgftransformyscale{#1/100bp}%
%
% Although the shading is a (scaled) rectangle the
% bounding box needs to be updated to the correct size
% which is done here using clipping.
\pgfpathrectangle{\pgfqpoint{0bp}{-50bp}}{\pgfqpoint{100bp}{100bp}}%
\pgfusepath{clip}%
\pgftransformshift{\pgfqpoint{50bp}{0bp}}%
\pgflowlevelsynccm%
\pgfuseshading{shaded.bar}%
\endpgfscope%
}}, decorate
}}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (5,5);
\draw [shading bar=5mm thick from red to orange] (0,0) -- (3,2);
\draw [shading bar=5mm thick from blue to cyan] (0,2) -- (2,5);
\draw [shading bar=10mm thick from green to yellow] (3,5) -- (5,0);
\end{tikzpicture}
\end{document}