# Example: Lambert-Beer law parameters drawing

Published 2012-01-11 | Author: Michele Muccioli

The Lambert-Beer law states there is a logarithmic dependence between the ratio between incident light intensity I0 and the intensity of scattered light directing forward I through a media and the product of the absorption coefficient γ of the substance and the distance the light travels through the material L.

I / I0 = exp(-γ L)

In the case of the figure below, the light is a red laser beam through a cloud formed by sand grains with a certain granulometry schematized with spherical particles.

To deep the argument (γ computation), see "Light scattering by small particles" by Hulst van de H.C., Dover Publications.

LuaLaTeX required for compilation.

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% Lambert-Beer law parameters drawing
% Author: Michele Muccioli
% Compile with LuaLaTeX
\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\pgfkeys{/pgf/decoration/.cd,
start color/.store in = \startcolor,
end color/.store in   = \endcolor
}

\pgfdeclaredecoration{color change}{initial}{
% Initial state
\state{initial}[%
width                     = 0pt,
next state                = line,
persistent precomputation = {\pgfmathdivide{50}{\pgfdecoratedpathlength}%
\let\increment=\pgfmathresult%
\def\x{0}}]%
{}%

% Line state
\state{line}[%
width                      = .5pt,
\let\x=\pgfmathresult}]%
{%
\pgfsetlinewidth{\pgflinewidth}%
\pgfsetarrows{-}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfpathlineto{\pgfqpoint{.75pt}{0pt}}%
\pgfsetstrokecolor{\endcolor!\x!\startcolor}%
\pgfusepath{stroke}%
}%

% Final state
\state{final}{%
\pgfsetlinewidth{\pgflinewidth}%
\pgfpathmoveto{\pgfpointorigin}%
\color{\endcolor!\x!\startcolor}%
\pgfusepath{stroke}%
}
}
\makeatother

%%%%%%%%%%%%
% COMMANDS %
%%%%%%%%%%%%
\def\pr#1{\directlua{tex.print(#1)}}

\def\rnd{.%
\pdfuniformdeviate10%
\pdfuniformdeviate10%
\pdfuniformdeviate10%
}

\begin{document}
%%%%%%%%%%%%%%
% PARAMETERS %
%%%%%%%%%%%%%%
\definecolor{sand}{RGB}{193,154,107} % Particles color
\def\cols{20}                        % Number of columns
\def\rows{40}                        % Number of rows
\def\SquareUnit{.35}                 % Lengths of unit square edges (cm)
\def\BeforeLight{5}                  % Light path before particle cloud
\begin{tikzpicture}[x          = \SquareUnit cm,
y          = \SquareUnit cm,
line width = 2pt
]
%%%%%%%%%%%%%%
% LIGHT PATH %
%%%%%%%%%%%%%%
%-> Before particles cloud
\draw[red,
decoration = {markings,
mark = at position 0.5 with {\arrow[]{latex}}},
postaction = {decorate}] (-\BeforeLight,{\rows*\SquareUnit/2})--++
(\BeforeLight,0)node[midway,
above,
black]{$I_0$};

%-> Trespassing particles cloud
\draw[decoration = {color change,
start color = red,
end color   = red!20!white},
decorate] (0,{\rows*\SquareUnit/2})--++
(\cols*\SquareUnit,0);

%-> After particles cloud
\draw[red!20!white,
decoration = {markings,
mark = at position 0.5 with {\arrow[]{latex}}},
postaction = {decorate}] ({\cols*\SquareUnit},{\rows*\SquareUnit/2})--++
(\BeforeLight,0)node[midway,
above,
black]{$I$};
%%%%%%%%%%%%%%%%%%%
% PARTICLES CLOUD %
%%%%%%%%%%%%%%%%%%%
%-> Lua version (FASTER)
\foreach \i in {1,...,\cols}{
\foreach \j in {1,...,\rows}{
}
}

%-> pgfmath version (uncomment it if you want to try)
% Some time compilation gives too high
% number computation problem
%\foreach \i in {1,...,\cols}{
%	\foreach \j in {1,...,\rows}{
%        }
%}

%%%%%%%%%%%%%%%%%%
% LENGTH QUOTING %
%%%%%%%%%%%%%%%%%%
\draw[|<->|,
>          = latex,
line width = .8pt] ($(0,\rows*\SquareUnit)+(0,1)$)--++
(\cols*\SquareUnit,0)node[midway,
above]{$L$};
%%%%%%%%%%%%%%%%%%%%
% LAMBERT-BEER LAW %
%%%%%%%%%%%%%%%%%%%%
\node[anchor    = north,
inner sep = 1ex] at (current bounding box.south){$\dfrac{I}{I_0}=\exp(-\gamma L)$};
\end{tikzpicture}
\end{document} 