[OS X TeX] Angular Vernier scale

Aaron Jackson jackson at msrce.howard.edu
Sun Jun 2 20:55:11 CEST 2013


On Jun 2, 2013, at 12:54 PM, Gary L. Gray <gray at psu.edu> wrote:

> On Jun 2, 2013, at 11:42 AM, Aaron Jackson <jackson at msrce.howard.edu> wrote:
> 
>> BTW, this is an updated version of my previous code for posterity:
>> 
>> % A simple compass
>> % Author: Dario Orescanin
>> 
>> \documentclass{minimal}
>> \usepackage{tikz}
>> \begin{document}
>> 
>> \begin{centering}
>> 
>> % Define a few constants for easy configuration
>> \def\radius{2cm}
>> \def\onedegrad{1.8cm}
>> \def\fivedegrad{1.75cm}
>> \def\tendegrad{1.7cm}
>> \def\labelrad{1.6cm}
>> 
>> \def\minradius{2.3cm}
>> \def\fifteenmin{2.2cm}
>> \def\fivemin{2.1cm}
>> \def\minlabel{2.25cm}
>> \def\vernierunit{1.9}
>> \def\verniercount{10}
>> \def\rotation{-26.7}
>> \def\zeroOffset{270}
>> 
>> \begin{tikzpicture}[scale=3.5]
>> \clip (-1.25,-2.4) rectangle (1.25,-1.25);
>>  % adding a subtle gray tone to add a bit of "personality"
>>  \shade[shading=radial, inner color=white, outer color=gray!15] (0,0) circle (\radius);
>> 
>>  \draw (0,0) circle (\radius);
>>  \draw[fill=black] (0,0) circle (.02mm);
>>  \node[draw, circle, inner sep=.2mm] (a) at (0,0) {};
>> 
>>  % helper lines
>> % \foreach \x in {0, 45, ..., 360} \draw[very thin, gray!40] (a) -- (\x+\rotation:\radius);
>> 
>>  % main lines
>>  \foreach \x in {0,...,359} \draw (\x+\rotation:\onedegrad) -- (\x+\rotation:\radius);
>> 
>>  % labels and longer lines at every 10 degrees
>>  \foreach \x in {0,10,...,350}
>>  {
>>    \node[scale=1.4] at (270-\x+\rotation:\labelrad) {\x};
>>    \draw (\x+\rotation:\tendegrad) -- (\x+\rotation:\radius);
>>  };
>> 
>>  % lines at every 5 degrees
>>  \foreach \x in {0,5,...,355}  \draw (\x+\rotation:\fivedegrad) -- (\x+\rotation:\radius);
>>   \draw (0,0) circle (\minradius);
>>   \foreach \x in {0,...,20} \draw  (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\radius) -- (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\fivemin);
>>   \foreach \x in {0,5,...,20} \draw  (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\radius) -- (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\fifteenmin);
>>   \pgfmathsetmacro{\y}{round(mod(10*\rotation,10))? round(mod(10*\rotation,10)) : 10};
>>   \node at (\zeroOffset:\minlabel) {0};
>>   \node at (\zeroOffset-\vernierunit*\verniercount:\minlabel) {60'};
>>   \node at (\zeroOffset+\vernierunit*\verniercount:\minlabel) {60'};
>>   \node at (\zeroOffset-\vernierunit*\verniercount+5*\vernierunit:\minlabel) {30'};
>>   \node at (\zeroOffset-\vernierunit*\verniercount+15*\vernierunit:\minlabel) {30'};
>>   \draw[red] (\zeroOffset:2*\radius-\fivemin) -- (\zeroOffset:\fivemin);
>>   \draw[red] (\zeroOffset-\vernierunit*\y:2*\radius-\fivemin) -- (\zeroOffset-\vernierunit*\y:\fivemin);
>>   \pgfmathtruncatemacro{\z}{\y}
>>   \pgfmathtruncatemacro{\a}{round(\rotation)};
>>   \ifnum\a=0\ifnum\z=10\draw[red] (\zeroOffset-\vernierunit*-\y:2*\radius-\fivemin) -- (\zeroOffset-\vernierunit*-\y:\fivemin);\fi\fi
>> \end{tikzpicture}
>> \end{centering}
>> \end{document}
> 
> I am keeping this. What a cool example.
> 
> Gary
> 

Thanks. Now that I know that you are paying attention to my code my OCD kicked in, so I fixed a small but and made a couple of changes and included comments. This is the final version:

% A simple compass
% Author: Dario Orescanin
% Modified to include a vernier scale
% Author: Aaron Jackson

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\begin{centering}

% Define a few constants for easy configuration
\def\radius{2cm}
\def\onedegrad{1.8cm}
\def\fivedegrad{1.75cm}
\def\tendegrad{1.7cm}
\def\labelrad{1.6cm}

 \def\minradius{2.3cm}
 \def\thirtymin{2.2cm}
 \def\fivemin{2.1cm}
 \def\minlabel{2.25cm}
 \def\vernierunit{1.9}
 \def\verniercount{10}
 \def\rotation{-10.1} % Change this to draw different angle settings. The angle should be to the nearest .1 degree. Negative rotations are OK.
 \def\zeroOffset{270}

\begin{tikzpicture}[scale=3.5]
\clip (-1.25,-2.4) rectangle (1.25,-1.25);
  % adding a subtle gray tone to add a bit of "personality"
  \shade[shading=radial, inner color=white, outer color=gray!15] (0,0) circle (\radius);

  \draw (0,0) circle (\radius);
  \draw[fill=black] (0,0) circle (.02mm);
  \node[draw, circle, inner sep=.2mm] (a) at (0,0) {};

  % main lines
  \foreach \x in {0,...,359} \draw (\x+\rotation:\onedegrad) -- (\x+\rotation:\radius);

  % labels and longer lines at every 10 degrees
  \foreach \x in {0,10,...,350}
  {
    \node[scale=1.4] at (270-\x+\rotation:\labelrad) {\x};
    \draw (\x+\rotation:\tendegrad) -- (\x+\rotation:\radius);
  };

  % lines at every 5 degrees
  \foreach \x in {0,5,...,355}  \draw (\x+\rotation:\fivedegrad) -- (\x+\rotation:\radius);
  
  %
  % vernier code
  %
  
  % draw the outer circle
   \draw (0,0) circle (\minradius);
   
   % draw the lines at every 6 minutes
   \foreach \x in {0,...,20} \draw  (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\radius) -- (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\fivemin);
   
   % draw the lines at every 30 minutes
   \foreach \x in {0,5,...,20} \draw  (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\radius) -- (\zeroOffset-\vernierunit*\verniercount+\x*\vernierunit:\thirtymin);
   
   % label the 30 minute lines
   \node at (\zeroOffset:\minlabel) {0};
   \node at (\zeroOffset-\vernierunit*\verniercount:\minlabel) {60'};
   \node at (\zeroOffset+\vernierunit*\verniercount:\minlabel) {60'};
   \node at (\zeroOffset-\vernierunit*\verniercount+5*\vernierunit:\minlabel) {30'};
   \node at (\zeroOffset-\vernierunit*\verniercount+15*\vernierunit:\minlabel) {30'};
   
   % calculate the decimal part of the rotation angle--needed for the vernier match below
   \pgfmathsetmacro{\y}{round(mod(10*\rotation,10)) ? round(mod(10*\rotation,10)) : (\rotation==abs(\rotation) ? 10 : -10)};
   
   % calculate integer value for the decimal part of the rotation angle--needed for the \ifnum test below
   \pgfmathtruncatemacro{\z}{abs(\y)}
   
   % calculate the integer value for the whole part of the rotation angle--needed for the \ifnum test below
   \pgfmathtruncatemacro{\a}{floor(\rotation)};
   
   % highlight the whole part of the rotation angle--the 0 point of the vernier
   \ifnum\z=10
     \draw[red,ultra thick,opacity=0.3] (\zeroOffset:2*\radius-\fivemin) -- (\zeroOffset:\fivemin); % vernier match i.e. x.0 degrees
   \else
     \draw[red] (\zeroOffset:2*\radius-\fivemin) -- (\zeroOffset:\fivemin); % somewhere between whole angles on the main scale
   \fi
   
   % highlight the vernier match
   \draw[red,ultra thick,opacity=0.3] (\zeroOffset-\vernierunit*\y:2*\radius-\fivemin) -- (\zeroOffset-\vernierunit*\y:\fivemin);
   
   % If there is no rotation make sure BOTH 60 minute lines are highlighted
   \ifnum\a=0\ifnum\z=10\draw[red,ultra thick,opacity=0.3] (\zeroOffset-\vernierunit*-\y:2*\radius-\fivemin) -- (\zeroOffset-\vernierunit*-\y:\fivemin);\fi\fi
\end{tikzpicture}
\end{centering}
\end{document}




More information about the macostex-archives mailing list