切掉部分径向阴影作为节点形状的扇形

切掉部分径向阴影作为节点形状的扇形

应将部分径向阴影剪掉。\clip(?)ed我想用这部分填充\predefined节点形状(此处:\nodemaerz)。抱歉我的英语不好。

适用\shade于两种颜色(此处:紫色黑色),但对我来说无法处理。一开始与\pgfdeclareradialshadingpgfman301a,第 1082 页中的使用相反。但我无法将\shade[inner colo and so on]“let”之前的替换为\pgfuseshading{sphere}。是的,两者都是不同的构造,因此语法无效。但我感觉期望的结果就在我眼前,但我无法解决它。

有谁可以帮忙吗?

当然,径向阴影必须延伸到所需的半径(s.code:径向阴影的 pgf 声明)。要点是:\node从扇形中心到圆弧中心剪切并用剪切出的阴影填充 maerz。

\documentclass[margin=100pt]{standalone}
\usepackage{tikz}     

\makeatletter
% from https://tex.stackexchange.com/a/127045/121799
\tikzset{use path/.code=\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}}
\makeatother

\usetikzlibrary{calc,shapes.geometric,backgrounds,fadings}

\tikzfading[name=fade in,inner color=transparent!10,outer color=transparent!10]

\pgfdeclareradialshading[fradialcolour1,fradialcolour2,fradialcolour3]
                     {fncyradial}{\pgfpoint{0}{0}}
                     {% manual 1082-1083; 
                      %later - shading is assumed to be 100bp diameter ??
                      color(0)=(fradialcolour1);
                      color(20bp)=(fradialcolour2);
                      color(40bp)=(fradialcolour3);
                      color(50bp)=(fradialcolour3)
                     }
\tikzset{% https://tex.stackexchange.com/a/372682/121799
fradial/.code={%
    \tikzset{%
        fancy radial/.cd,
        shading=fncyradial,
        #1
    }
},%end fradial/.co...
fancy radial/.search also={/tikz},
fancy radial/.cd,
%
fancy radial inner colour/.code={\colorlet{fradialcolour1}{#1}},
fancy radial mid colour/.code={\colorlet{fradialcolour2}{#1}},
fancy radial outer colour/.code={\colorlet{fradialcolour3}{#1}},
%
fancy radial inner colour=black,
fancy radial outer colour=red,
fancy radial mid colour=violet,
inner color/.style={
    fancy radial inner colour=#1,
},
outer color/.style={
    fancy radial outer colour=#1,
},
mid color/.style={
    fancy radial mid colour=#1,
},
}%end tikzset

\begin{document}  

\begin{tikzpicture}[scale=1.0,transform shape] 

\tikzset{shape circlesec/.style={
        draw,
        line width=0.1pt,
        inner xsep=0pt,
        inner ysep=0pt,
    } 
}%end tikzset


\node [name=maerz,
       save path=\pathA,
       shape=circular sector, 
       style=shape circlesec,
       inner sep=0cm,
       circular sector angle=30,
       shape border uses incircle,
       shape border rotate=-165,
       anchor=sector center,inner sep=-2mm,%
       minimum size = 6.6cm,%has an effect if the original size was smaller
      ] 
   (maerz) at (0,0) {};

    \pgfdeclareradialshading{sphere}%shading name
                            {\pgfpoint{0}{0}}%center point pgfman301a,p.1083
                            {rgb(0.00cm)=(1.00,0.00,0.00); %color specification
                             rgb(1.70cm)=(0.60,1.00,0.00);
                             rgb(2.50cm)=(0.30,1.60,1.00);
                             rgb(3.00cm)=(0.00,0.30,1.50) %extent of the circle
                            }
   \begin{scope}[on background layer]
      \pgfuseshading{sphere};
      % HOW integrate the \node name=maerz here instaed of shade???
      % changing the \shade [option] with \pfgdeclareradialshading{sphere} doesn't work
      \clip[use path=\pathA];
      \shade[inner color=black,% third color not usable?
             outer color=violet,
             %mid color=green,%not usable?
             path fading=fade in
         ] %the lengths here i want use for the \node nmae=maerz
         let \p1=($(maerz.arc center)-(maerz.sector center)$),
             \n1={veclen(\y1,\x1)}
              in (maerz.sector center) circle (\n1);
\end{scope}

\foreach \anchor/\placement in
   {arc center/right, sector center/below left}
      \draw[shift=(maerz.\anchor)] plot[mark=x] coordinates{(0,0)}
           node[\placement] {\scriptsize\texttt{(maerz.\anchor)}};  

\draw let \p1=($(maerz.north)-(maerz.sector center)$),\n1={int(1+\y1*1pt/1cm)}%
   in
   \pgfextra{\pgfmathtruncatemacro{\xmax}{\n1}
             \pgfmathtruncatemacro{\nextx}{\xmax-1}
            }%end pgfextra code
   foreach \x in {-\xmax,-\nextx,...,\xmax}
      {(\x,1pt) -- (\x,-1pt) node[anchor=north,font=\tiny]{ $\x$} } 
   foreach \y in {-\xmax,-\nextx,...,\xmax}
      {(1pt,\y) -- (-1pt,\y) node[anchor=east,font=\tiny]{($\y$)}};

\end{tikzpicture} 
\end{document}

圆的一部分应为扇形形状的节点。

答案1

经过反复尝试,我找到了一种在 中实现阴影的方法path picture。不再如此calc,现在一切都是简单的样式

       shade radial={
        shade radial color={1}{black},
        shade radial color={2}{green},
        shade radial color={3}{blue},
        shade radial color={4}{red}
        },

您可以将其添加到节点。

在此处输入图片描述

(阴影被称为color four radial而不是four color radial承认cfr 的开创性工作

梅威瑟:

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\tikzset{shade radial/.code={%
        \tikzset{%
          color four radial/.cd,% I know "four color radial" sounds better but cfr should be acknowledged here
          #1,
          cfradial
        }},
color four radial/.cd,  
shade radial color/.code n args={2}{\colorlet{cfradialcolor#1}{#2}},
shade radial color={1}{black},
shade radial color={2}{black},
shade radial color={3}{white},
shade radial color={4}{white},
cfradial/.style={/tikz/path picture={
\xdef\radius{\radius}
\pgfmathsetmacro{\rone}{0.6*\radius}
\pgfmathsetmacro{\rtwo}{0.8*\radius}
\pgfdeclareradialshading[cfradialcolor1,cfradialcolor2,cfradialcolor3,cfradialcolor4]{cfradial}%shading name see pgfmanual 3.01a, p. 1083
                            {\centerpoint}%center point 
                            {color(0pt)=(cfradialcolor1); %color specifications
                             color(\rone pt)=(cfradialcolor2);
                             color(\rtwo pt)=(cfradialcolor3);
                             color(\radius)=(cfradialcolor4) %
                            }
\typeout{\radius,\rone,\rtwo}
\pgfuseshading{cfradial}
}}}

\begin{document}  
\begin{tikzpicture}
\tikzset{shape circlesec/.style={
        draw,
        line width=0.1pt,
        inner xsep=0pt,
        inner ysep=0pt,
    } 
}
\node [shape=circular sector, 
       style=shape circlesec,
       inner sep=0cm,
       shade radial={
        shade radial color={1}{black},
        shade radial color={2}{green},
        shade radial color={3}{blue},
        shade radial color={4}{red}
        },
       circular sector angle=30,
       shape border uses incircle,
       shape border rotate=-165,
       anchor=sector center,inner sep=-2mm,%
       minimum size = 6.6cm,%has an effect if the original size was smaller
      ] 
   (maerz) at (0,0) {};
\end{tikzpicture} 
\end{document}

旧答案:我试图回答这个好问题。我认为这是一个非常按照您建议的方式使用,这是一个聪明的想法\pgfdeclareradialshading。我所做的只是清理一下,并编写了一个 pgfkeys 代码,该代码根据可以提取的某些输入声明阴影,例如通过calc。我还剔除了对问题可能不重要的元素,例如网格。

\documentclass[margin=100pt]{standalone}
\usepackage{tikz}     
\makeatletter
% from https://tex.stackexchange.com/a/127045/121799
\tikzset{use path/.code=\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}}
\makeatother
\usetikzlibrary{calc,shapes.geometric,backgrounds,fadings}
\tikzset{my radial shader/.code args={#1 with radius #2}{
\pgfmathsetmacro{\rone}{0.6*#2}
\pgfmathsetmacro{\rtwo}{0.8*#2}
\typeout{#1:\rone,#2}
\pgfdeclareradialshading{#1}%shading name
                            {\pgfpoint{0}{0}}%center point pgfman301a,p.1083
                            {rgb(0pt)=(1.00,0.00,0.00); %color specification
                             rgb(\rone pt)=(0.60,1.00,0.00);
                             rgb(\rtwo pt)=(0.30,1.60,1.00);
                             rgb(#2)=(0.00,0.30,1.50) %extent of the circle
                            }
}}

\begin{document}  
\begin{tikzpicture}
\tikzset{shape circlesec/.style={
        draw,
        line width=0.1pt,
        inner xsep=0pt,
        inner ysep=0pt,
    } 
}
\node [save path=\pathA,
       shape=circular sector, 
       style=shape circlesec,
       inner sep=0cm,
       circular sector angle=30,
       shape border uses incircle,
       shape border rotate=-165,
       anchor=sector center,inner sep=-2mm,%
       minimum size = 6.6cm,%has an effect if the original size was smaller
      ] 
   (maerz) at (0,0) {};

   \begin{scope}[on background layer]
   \path    let \p1=($(maerz.arc center)-(maerz.sector center)$),
             \n1={veclen(\y1,\x1)} in 
             [my radial shader={rad1 with radius \n1}];
   \clip[use path=\pathA];               
   \pgfuseshading{rad1};
   \end{scope}
\end{tikzpicture} 
\end{document}

在此处输入图片描述

我相信这可以通过path picture等来简化很多。但这至少是可行的。

相关内容