10

I would like to draw a mirror and its thickness, using Tikz. I'll show you the final result I'd like to achieve

enter image description here

I managed to write this code (using tikz package)

    \shade[shading angle= 90] (75:3)
    -- (75:3.5) arc (75:-75:3.5)
    -- (-75:3) arc (-75:75:3);

which gives back this picture

I wish to have a different shading effect, like a ring one. Can someone help me please? Thank you in advance.

ADDENDUM: I'm gettin really mad. I tried to swap inner color with outer color to obtain this effect

enter image description here

but this is what actually latex gives me back

enter image description here

I'll leave you the code I used

\tikzfading[name=fade out,inner color=transparent!100,outer color=transparent!0]
\begin{scope}[xshift=6cm]
    \clip (75:-3)
    -- (75:-2.5) arc (75:-75:-2.5)
    -- (-75:-3) arc (-75:75:-3);
    \fill[path fading=fade out] (0,0) circle[radius=-3];
\end{scope}

If I keep outer and inner colors like the case before, I obtain this

enter image description here

I'm not understading why tikz is acting like this. Theoretically if I swap the colors, I should get what I am supposed to get, but I'm clearly wrong and I don't know why.

  • I added a shading halo to address the second part of your problem in an addendum to my answer. – user194703 Dec 17 '19 at 22:02
22

Welcome! These are two basic options from the pgfmanual:

  • circle with fuzzy edge 15 percent
  • fade out

Example:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{fadings}
\tikzfading[name=fade out,inner color=transparent!0,outer color=transparent!100]
\begin{document}
\begin{tikzpicture}
 \begin{scope}
 \clip (75:3)
    -- (75:3.5) arc (75:-75:3.5)
    -- (-75:3) arc (-75:75:3);
  \fill[path fading=circle with fuzzy edge 15 percent] (0,0) circle[radius=3.5cm];
 \end{scope}    
 \begin{scope}[xshift=5cm]
 \clip (75:3)
    -- (75:3.5) arc (75:-75:3.5)
    -- (-75:3) arc (-75:75:3);
  \fill[path fading=fade out] (0,0) circle[radius=3.5cm];
 \end{scope}    
\end{tikzpicture}
\end{document}

enter image description here

You can use this e.g. as follows:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{contour}
\contourlength{0.05em}
\usetikzlibrary{fadings,decorations.markings,calc,angles,quotes}
\tikzset{->-/.style={decoration={% https://tex.stackexchange.com/a/39282/194703
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}},
  ->-/.default=0.5}
\begin{document}
\begin{tikzpicture}[>=stealth,every label/.append style={black},
    bullet/.style={circle,fill=black,inner sep=0.1em}]
 \begin{scope}
 \clip (75:3)
    -- (75:3.5) arc (75:-75:3.5)
    -- (-75:3) arc (-75:75:3);
  \fill[path fading=circle with fuzzy edge 15 percent] (0,0) circle[radius=3.5cm];
 \end{scope}
 \draw (-3,0) coordinate (L) -- (4,0) coordinate (R) (3,0)
  node[bullet,label=below right:\contour{white}{$V$}](V){};
 \pgfmathsetmacro{\myangle}{atan2(3*sin(30),2+3*cos(30))}
 \draw[thick,orange,->-] (-2,0) node[bullet,label=below:$O$](O){} 
    -- (30:3) node[bullet,label={above right:\contour{white}{$P$}}] (P){};  
 \draw[dashed,blue] (0,0) node[bullet,label=below:$C$] (C){} -- (P);
 \path[overlay] (P) -- ++ (180+60-\myangle:1) coordinate (Q);
 \draw[thick,red,->-] (P) -- 
  (intersection cs:first line={(L)--(R)}, second line={(P)--(Q)}) 
  node[bullet,label=below:$I$] (I){};
 \path[blue]  
 pic [draw, "$\scriptstyle\alpha$",angle eccentricity=1.25,angle radius=1cm] {angle=R--O--P}
 pic [draw, "$\scriptstyle\beta$",angle eccentricity=0.7,angle radius=0.8cm] {angle=R--C--P}
 pic [draw, "$\scriptstyle\gamma$",angle eccentricity=0.7,angle radius=0.8cm] {angle=R--I--P};
\end{tikzpicture}
\end{document}

enter image description here

Or declare your own.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{contour}
\contourlength{0.05em}
\usetikzlibrary{fadings,decorations.markings,calc,angles,quotes}
\pgfdeclareradialshading{invircle}{\pgfpointorigin}{
  color(0pt)=(pgftransparent!100); color(22.5bp)=(pgftransparent!80);
  color(25bp)=(pgftransparent!20); color(50bp)=(pgftransparent!00)}%
\pgfdeclarefading{inverted fading}{\pgfuseshading{invircle}}%

\tikzset{->-/.style={decoration={% https://tex.stackexchange.com/a/39282/194703
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}},
  ->-/.default=0.5}
\begin{document}
\begin{tikzpicture}[>=stealth,every label/.append style={black},
    bullet/.style={circle,fill=black,inner sep=0.1em}]
 \begin{scope}
 \clip (75:3)
    -- (75:3.5) arc (75:-75:3.5)
    -- (-75:3) arc (-75:75:3);
  \fill[path fading=inverted fading] (0,0) circle[radius=3.5cm];
 \end{scope}
 \draw (-3,0) coordinate (L) -- (4,0) coordinate (R) (3,0)
  node[bullet,label=below right:\contour{white}{$V$}](V){};
 \pgfmathsetmacro{\myangle}{atan2(3*sin(30),2+3*cos(30))}
 \draw[thick,orange,->-] (-2,0) node[bullet,label=below:$O$](O){} 
    -- (30:3) node[bullet,label={above right:\contour{white}{$P$}}] (P){};  
 \draw[dashed,blue] (0,0) node[bullet,label=below:$C$] (C){} -- (P);
 \path[overlay] (P) -- ++ (180+60-\myangle:1) coordinate (Q);
 \draw[thick,red,->-] (P) -- 
  (intersection cs:first line={(L)--(R)}, second line={(P)--(Q)}) 
  node[bullet,label=below:$I$] (I){};
 \path[blue]  
 pic [draw, "$\scriptstyle\alpha$",angle eccentricity=1.25,angle radius=1cm] {angle=R--O--P}
 pic [draw, "$\scriptstyle\beta$",angle eccentricity=0.7,angle radius=0.8cm] {angle=R--C--P}
 pic [draw, "$\scriptstyle\gamma$",angle eccentricity=0.7,angle radius=0.8cm] {angle=R--I--P};
\end{tikzpicture}
\end{document}

enter image description here

ADDENDUM: As for the addendum to your question: here is a shading that produces something of that sort. It was obtained by looking up the definition of circle with fuzzy edge 10 percent and to "invert it", as you suggest.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings,calc,angles,quotes}
\pgfdeclareradialshading{halo}{\pgfpointorigin}{
  color(0pt)=(pgftransparent!100); color(22.5bp)=(pgftransparent!100);
  color(25bp)=(pgftransparent!00); color(50bp)=(pgftransparent!00)}%
\pgfdeclarefading{halo}{\pgfuseshading{halo}}%
\tikzset{->-/.style={decoration={% https://tex.stackexchange.com/a/39282/194703
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}},
  ->-/.default=0.5}
\begin{document}
\begin{tikzpicture}[>=stealth,every label/.append style={black},
    bullet/.style={circle,fill=black,inner sep=0.1em}]
\begin{scope}[xshift=6cm]
    \clip (75:-3)
    -- (75:-2.5) arc (75:-75:-2.5)
    -- (-75:-3) arc (-75:75:-3);
    \fill[path fading=halo] (0,0) circle[radius=3cm];
\end{scope}
\draw (-2,0) coordinate (L) -- (7,0) coordinate (R) 
  (3,0)  node[bullet,label=below left:$V$](V){}
  (6,0)  node[bullet,label=below:$C$](C){}
  (-1,0)  node[bullet,label=below:$O$](O){}
  ($(C)+(160:3)$) node[bullet,label=above:$P$](P){};
  \draw[orange,->-,thick] (O) -- (P);
  \draw[red,->-,thick] let \p1=($(P)-(C)$),\p2=($(P)-(O)$),
   \n1={180-atan2(\y1,\x1)},\n2={atan2(\y2,\x2)} in
  (P) -- ++({180-(2*\n1+\n2)}:2);
  \draw[dashed, shorten >=-2cm] (C) -- (P);
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • thank you, much appreciated – frad Dec 16 '19 at 22:15
  • 2
    @user203430 Remember to mark this answer as accepted if you think it adequately answered your question! – sintax Dec 17 '19 at 19:16
  • is there any way to get the shading like the one obtained with the first method? Why if I swap inner with outer color, I got that result? – frad Dec 18 '19 at 11:03
  • @user203430 Please note that fade out fades out over the full radius. However, we clip only a tiny shell of the circle, along which the color does not vary very much. If you remove the \clip ....; you will see what I mean. – user194703 Dec 18 '19 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.