how to highlight (with glow) any path using Tikz?
I made a glow
style, that simply draws the line several times with increasing thickness and and low opacity. The glow can be a different color from the line. If the line has an arrow it look strange, but you can simply draw it first with glow, and the again with the arrow.
\documentclass[,varwidth,border=1pt]{standalone}
\usepackage[dvipsnames,svgnames,x11names,]{xcolor}
\usepackage{pgf,tikz,tikz-3dplot}
\tikzset{%
glow/.style={%
preaction={#1, draw, line join=round, line width=0.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=1.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=1.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=2.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=2.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=3.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=3.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=4.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=4.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=5.0pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=5.5pt, opacity=0.04,
preaction={#1, draw, line join=round, line width=6.0pt, opacity=0.04,
}}}}}}}}}}}}}}
\begin{document}
\begin{tikzpicture}[ >=latex]
\draw[->] (-4,0)--(5,0) node[at end,above]{$x$};
\draw[->] (0,-1,0)--(0,5,0) node[at end,right]{$y$};
\draw[->] (0,0) coordinate(O) -- ({5*cos(30)},{5*sin(30)}) coordinate (XP) node[pos=1.1]{$x'$};
\draw[->] (O) -- ({-5*sin(30)},{5*cos(30)}) coordinate (YP) node[pos=1.1]{$y'$};
\draw[->, red, glow=red] (O) -- ({4*cos(50)}, {4*sin(50)}) coordinate(R);
\draw[blue, glow=orange] (R)|-coordinate (Q) (O);
\draw[glow=cyan] (O) -- ({4*cos(50)*cos(30)*cos(30)}, {4*cos(50)*cos(30)*sin(30)})-- (Q) -- cycle;
\draw[<->, Orchid] (1.25,0) arc (0:30:1.25cm) node[midway, right ]{$\theta_{11}$};
\draw[<->, Firebrick2] (30:1.25) arc (30:50:1.25cm) node[midway, right ]{$\theta_{12}$};
\draw[glow=yellow] (Q)--++({ 4*sin(50)*sin(30)*cos(30) }, { 4*sin(50)*sin(30)*sin(30) } )-- (R);
\end{tikzpicture}
\end{document}
Careful consideration needs to be taken on the order of the lines and glows, so that they are not painted on top of each other. Like in this zoom:
The easiest way to avoid problems are to draw all glows first(or on a background layer) and then the normal lines.
Edit:
This glow has rounded ends, and do not overwrite the original lines. Using the solution from Pass options to the scope that is internally created by preaction:
\documentclass[tikz, border=0.1 cm]{standalone}
\pgfdeclarelayer{back}
\pgfsetlayers{back,main}
\makeatletter
\pgfkeys{%
/tikz/on layer/.code={
\pgfonlayer{#1}\begingroup
\aftergroup\endpgfonlayer
\aftergroup\endgroup
},
/tikz/node on layer/.code={
\pgfonlayer{#1}\begingroup
\expandafter\def\expandafter\tikz@node@finish\expandafter{\expandafter\endgroup\expandafter\endpgfonlayer\tikz@node@finish}%
},
}
\tikzset{%
glow/.style={%
preaction={#1, draw, line cap=round, line join=round, line width=0.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=1.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=1.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=2.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=2.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=3.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=3.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=4.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=4.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=5.0pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=5.5pt, opacity=0.04, on layer=back,
preaction={#1, draw, line cap=round, line join=round, line width=6.0pt, opacity=0.04, on layer=back,
}}}}}}}}}}}}}}
\begin{document}
\begin{tikzpicture}
\draw[glow=red] (0,0.5) -- (1,0.5);
\draw[glow=red] (0.5,0) -- (0.5,1);
\end{tikzpicture}
\end{document}
Zoom:
Random glowing lines:
You can just draw some thick line in the background. This can be done either with the backgrounds
library, by a preaction
, just drawing the thick lines earlier, or combinations of these. If you set the opacity to nontrivial values, it can make sense to use a transparency
group.
\documentclass[,varwidth,border=1pt]{standalone}
\usepackage[dvipsnames,svgnames,x11names,]{xcolor}
\usepackage{tikz}
%
\begin{document}
%
\begin{tikzpicture}[ >=latex,glow/.style={%
preaction={draw,line cap=round,line join=round,
opacity=0.3,line width=4pt,#1}},glow/.default=yellow,
transparency group]
\draw[->] (-4,0)--(5,0) node[at end,above]{$x$};
\draw[->] (0,-1,0)--(0,5,0) node[at end,right]{$y$};
\draw[->] (0,0) coordinate(O) -- ({5*cos(30)},{5*sin(30)}) coordinate (XP) node[pos=1.1]{$x'$};
\draw[->] (O) -- ({-5*sin(30)},{5*cos(30)}) coordinate (YP) node[pos=1.1]{$y'$};
\draw[->, red] (O) -- ({4*cos(50)}, {4*sin(50)}) coordinate(R);
\draw[glow] (R) -- (R|-O)coordinate (Q);
\draw[glow={cyan!50}] (Q) -- (O) --
({4*cos(50)*cos(30)*cos(30)},{4*cos(50)*cos(30)*sin(30)}) coordinate (A) -- cycle;
\draw[blue] (R)|- (O);
\draw[green] (O) -- (A)-- (Q);
\draw[<->, Orchid] (1.25,0) arc (0:30:1.25cm) node[midway, right ]{$\theta_{11}$};
\draw[<->, Firebrick2] (30:1.25) arc (30:50:1.25cm) node[midway, right ]{$\theta_{12}$};
\draw[orange,glow] (Q)--++({ 4*sin(50)*sin(30)*cos(30) }, { 4*sin(50)*sin(30)*sin(30) } )
coordinate (B)-- (R);
\end{tikzpicture}
%
\end{document}