Drawing power crosses in LaTeX

Posted: 10th September 2015 by Tim in LaTeX, Optics
Tags: , , , , , , , ,

Power crosses are useful diagrams for doing lens power calculations in optics. Drawing the power crosses in LaTeX can be tedious, especially if you need to draw multiple power crosses in the same document. The code below creates a new command, \powercross{front@90}{front@180}{back@90}{back@180}, which will draw the power crosses for you and calculate the final lens power based on the powers of the front and back lens surfaces. All values will be rounded to two decimal places.

Note: you need have \usepackage{fp} in the preamble in order for this code to work.

% usage: \powercross{front@90}{front@180}{back@90}{back@180} \newcommand{\powercross}[4]{     \setlength{\unitlength}{1mm}     \vspace{1em}     \begin{picture}(135,35)         % crosses         \multiput(0,17.5)(50,0){3}{\line(1,0){35}}         \multiput(17.5,0)(50,0){3}{\line(0,1){35}}

        % arithmetic symbols         \put(41.5,16.5){\makebox{$+$}}         \put(91.5,16.5){\makebox{$=$}}

        % calculate resulting lens (requires fp)         \FPeval{\frontninety}{round(#1:2)}         \FPeval{\frontzero}{round(#2:2)}         \FPeval{\backninety}{round(#3:2)}         \FPeval{\backzero}{round(#4:2)}         \FPeval{\lensninety}{round(\frontninety+\backninety:2)}         \FPeval{\lenszero}{round(\frontzero+\backzero:2)}

        % labels         \put(18.5,33){\makebox{{\frontninety}D}}         \put(30.5,19){\makebox{{\frontzero}D}}         \put(68.5,33){\makebox{{\backninety}D}}         \put(80.5,19){\makebox{{\backzero}D}}         \put(118.5,33){\makebox{{\lensninety}D}}         \put(130.5,19){\makebox{{\lenszero}D}}     \end{picture}     \newline }

For example, this code:

\powercross{3.25}{3.25}{-10.25}{-7}

will produce the following: