\usepackage{xltxtra}
\usepackage[top=13pt, bottom=12pt, left=13pt, right=12pt]{geometry}
\usepackage{tikz}
\usepackage{lscape}

\usetikzlibrary{intersections}

\newcommand\grid[3]{
  \def\xmax{#1};
  \def\ymax{#2};
  \def\mycolor{#3};

  % Draw the grid
  \draw[step=1mm,  \mycolor,line width=0.1pt] (0,0) grid (\xmax,\ymax);
  \draw[step=0.5cm,\mycolor,line width=0.3pt ] (0,0) grid (\xmax,\ymax);
  \draw[step=1cm,  \mycolor,line width=0.6pt ] (0,0) grid (\xmax,\ymax);
}

\newcommand\vlin[5]{
  \def\xmax{#1};
  \def\ymax{#2};
  \def\rep{#3};
  \def\subdiv{#4};
  \def\mycolor{#5};

  \pgfmathtruncatemacro\repM{\rep-1}
  \pgfmathtruncatemacro\subdivM{\subdiv-1}

  % Draw the first line
  \draw[\mycolor, line width=0.9pt] (0,0) -- (0,\ymax);

  \foreach \z in {0,...,\repM}{
    \pgfmathsetmacro\xoffset{\xmax/\rep*\z}
    \pgfmathsetmacro\xwidth {\xmax/\rep}

    % Draw the main lines
    \draw[\mycolor, line width=0.9pt] ({\xoffset + \xwidth},0) -- ({\xoffset + \xwidth},\ymax);

    % Draw the secondary lines
    \draw[\mycolor, line width=0.6pt] ({\xoffset + 0.5*\xwidth},0) -- ({\xoffset + 0.5*\xwidth},\ymax);

    % Draw the subdivision lines
    \foreach \y in {1,...,\subdivM}{
      \draw[\mycolor, line width=0.1pt] ({\xoffset + \y*\xwidth/\subdiv},0) -- ({\xoffset + \y*\xwidth/\subdiv},\ymax);
    }
  }
}

\newcommand\hlin[5]{
  \def\xmax{#1};
  \def\ymax{#2};
  \def\rep{#3};
  \def\subdiv{#4};
  \def\mycolor{#5};

  \pgfmathtruncatemacro\repM{\rep-1}
  \pgfmathtruncatemacro\subdivM{\subdiv-1}

  % Draw the first line
  \draw[\mycolor, line width=0.9pt] (0,0) -- (\xmax,0);

  \foreach \z in {0,...,\repM}{
    \pgfmathsetmacro\xoffset{\ymax/\rep*\z}
    \pgfmathsetmacro\xwidth {\ymax/\rep}

    % Draw the main lines
    \draw[\mycolor, line width=0.9pt] (0,{\xoffset + \xwidth}) -- (\xmax,{\xoffset + \xwidth});

    % Draw the secondary lines
    \draw[\mycolor, line width=0.6pt] (0,{\xoffset + 0.5*\xwidth}) -- (\xmax,{\xoffset + 0.5*\xwidth});

    % Draw the subdivision lines
    \foreach \y in {1,...,\subdivM}{
      \draw[\mycolor, line width=0.1pt] (0,{\xoffset + \y*\xwidth/\subdiv}) -- (\xmax,{\xoffset + \y*\xwidth/\subdiv});
    }
  }
}

\newcommand\vlog[8]{
  \def\xmax{#1};
  \def\ymax{#2};
  \def\rep{#3};
  \def\mycolor{#8};

  % Draw the first line
  \draw[\mycolor, line width=0.9pt] (0,0) -- (0,\ymax);

  \pgfmathtruncatemacro\repM{\rep-1}

  \foreach \z in {0,...,\repM}{
    \pgfmathsetmacro\offset{\xmax/\rep*\z}
    \pgfmathsetmacro\width {\xmax/\rep}

    \foreach \x in {#4}{
      % Draw the main + secondary lines
      \draw[\mycolor, line width=0.9pt] ({\offset + log10(\x)*\width},0) node[anchor=north] {\tiny $\x$} -- ({\offset + log10(\x)*\width},\ymax);
      \draw[\mycolor, line width=0.6pt] ({\offset + log10(\x-0.5)*\width},0) -- ({\offset + log10(\x-0.5)*\width},\ymax);

      % Draw the subdivision lines (10)
      \foreach \y in {1,2,3,4,5,6,7,8,9}{
        \draw[\mycolor, line width=0.1pt] ({\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/10*\width},0) -- ({\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/10*\width},\ymax);
        \draw[\mycolor, line width=0.1pt] ({\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/10*\width},0) -- ({\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/10*\width},\ymax);
      }
    }

    \foreach \x in {#5}{
      % Draw the main + secondary lines
      \draw[\mycolor, line width=0.9pt] ({\offset + log10(\x)*\width},0) node[anchor=north] {\tiny $\x$} -- ({\offset + log10(\x)*\width},\ymax);
      \draw[\mycolor, line width=0.6pt] ({\offset + log10(\x-0.5)*\width},0) -- ({\offset + log10(\x-0.5)*\width},\ymax);

      % Draw the subdivision lines (5)
      \foreach \y in {1,2,3,4}{
        \draw[\mycolor, line width=0.1pt] ({\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/5*\width},0) -- ({\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/5*\width},\ymax);
        \draw[\mycolor, line width=0.1pt] ({\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/5*\width},0) -- ({\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/5*\width},\ymax);
      }
    }

    \foreach \x in {#6}{
      % Draw the main lines
      \draw[\mycolor, line width=0.9pt] ({\offset + log10(\x)*\width},0) node[anchor=north] {\tiny $\x$} -- ({\offset + log10(\x)*\width},\ymax);

      % Draw the subdivision lines (10)
      \foreach \y in {1,2,3,4,5,6,7,8,9}{
        \draw[\mycolor, line width=0.1pt] ({\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/10*\width},0) -- ({\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/10*\width},\ymax);
      }
    }

    \foreach \x in {#7}{
      % Draw the main lines
      \draw[\mycolor, line width=0.9pt] ({\offset + log10(\x)*\width},0) node[anchor=north] {\tiny $\x$} -- ({\offset + log10(\x)*\width},\ymax);

      % Draw the subdivision lines (5)
      \foreach \y in {1,2,3,4}{
        \draw[\mycolor, line width=0.1pt] ({\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/5*\width},0) -- ({\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/5*\width},\ymax);
      }
    }
  }
}

\newcommand\hlog[8]{
  \def\xmax{#1};
  \def\ymax{#2};
  \def\rep{#3};
  \def\mycolor{#8};

  % Draw the first line
  \draw[\mycolor, line width=0.9pt] (0,0) -- (\xmax,0);

  \pgfmathtruncatemacro\repM{\rep-1}

  \foreach \z in {0,...,\repM}{
    \pgfmathsetmacro\offset{\ymax/\rep*\z}
    \pgfmathsetmacro\width {\ymax/\rep}

    \foreach \x in {#4}{
      % Draw the main + secondary lines
      \draw[\mycolor, line width=0.9pt] (0,{\offset + log10(\x)*\width}) node[anchor=east] {\tiny $\x$} -- (\xmax,{\offset + log10(\x)*\width});
      \draw[\mycolor, line width=0.6pt] (0,{\offset + log10(\x-0.5)*\width}) -- (\xmax,{\offset + log10(\x-0.5)*\width});

      % Draw the subdivision lines (10)
      \foreach \y in {1,2,3,4,5,6,7,8,9}{
        \draw[\mycolor, line width=0.1pt] (0,{\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/10*\width}) -- (\xmax,{\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/10*\width});
        \draw[\mycolor, line width=0.1pt] (0,{\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/10*\width}) -- (\xmax,{\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/10*\width});
      }
    }

    \foreach \x in {#5}{
      % Draw the main + secondary lines
      \draw[\mycolor, line width=0.9pt] (0,{\offset + log10(\x)*\width}) node[anchor=east] {\tiny $\x$} -- (\xmax,{\offset + log10(\x)*\width});
      \draw[\mycolor, line width=0.6pt] (0,{\offset + log10(\x-0.5)*\width}) -- (\xmax,{\offset + log10(\x-0.5)*\width});

      % Draw the subdivision lines (5)
      \foreach \y in {1,2,3,4}{
        \draw[\mycolor, line width=0.1pt] (0,{\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/5*\width}) -- (\xmax,{\offset + log10(\x-1)*\width + \y*log10((\x-0.5)/(\x-1))/5*\width});
        \draw[\mycolor, line width=0.1pt] (0,{\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/5*\width}) -- (\xmax,{\offset + log10(\x-0.5)*\width + \y*log10((\x)/(\x-0.5))/5*\width});
      }
    }

    \foreach \x in {#6}{
      % Draw the main lines
      \draw[\mycolor, line width=0.9pt] (0,{\offset + log10(\x)*\width}) node[anchor=east] {\tiny $\x$} -- (\xmax,{\offset + log10(\x)*\width});

      % Draw the subdivision lines (10)
      \foreach \y in {1,2,3,4,5,6,7,8,9}{
        \draw[\mycolor, line width=0.1pt] (0,{\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/10*\width}) -- (\xmax,{\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/10*\width});
      }
    }

    \foreach \x in {#7}{
      % Draw the main lines
      \draw[\mycolor, line width=0.9pt] (0,{\offset + log10(\x)*\width}) node[anchor=east] {\tiny $\x$} -- (\xmax,{\offset + log10(\x)*\width});

      % Draw the subdivision lines (5)
      \foreach \y in {1,2,3,4}{
        \draw[\mycolor, line width=0.1pt] (0,{\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/5*\width}) -- (\xmax,{\offset + log10(\x-1)*\width + \y*log10((\x)/(\x-1))/5*\width});
      }
    }
  }
}
\newcommand\polar[3]{
  \pgfmathtruncatemacro\xmin{-#1/2}
  \pgfmathtruncatemacro\xmax{#1/2}
  \pgfmathtruncatemacro\ymin{-#2/2}
  \pgfmathtruncatemacro\ymax{#2/2}
  \def\mycolor{#3}

  \begin{scope}
  % Draw the border
  \draw[\mycolor, line width=0.9pt,name path global=border] (\xmin,\ymin) rectangle (\xmax,\ymax);
  \clip (\xmin,\ymin) rectangle (\xmax,\ymax);

  % Draw the cross
  \draw[\mycolor, line width=0.9pt] (-0.15,0) -- (0.15,0);
  \draw[\mycolor, line width=0.9pt] (0,-0.15) -- (0,0.15);

  % Draw the circles
  \draw[\mycolor, line width=0.9pt] (0,0) circle (0.2);

  \foreach \x in {1,...,25}{
    % Main
    \draw[\mycolor, line width=0.9pt] (0,0) circle (\x);

    % Subdivision
    \foreach \y in {1,...,4}{
      \draw[\mycolor, line width=0.1pt] (0,0) circle (\x - \y/5);
    }
  }

  % Draw the radial lines
  \foreach \x in {0,10,...,360}{
    % Main
    \draw[\mycolor, line width=0.9pt,name path global=\x] (\x:0.2) -- (\x:25);

    % Secondary
    \draw[\mycolor, line width=0.6pt] (\x + 5:1) -- (\x + 5:2);

    % Subdivision
    \foreach \y in {2,4,...,8}{
      \draw[\mycolor, line width=0.1pt] (\x + \y:2) -- (\x + \y:4);
    }

    % Secondary + Subdivision
    \draw[\mycolor, line width=0.6pt] (\x + 5:4) -- (\x + 5:25);
    \foreach \y in {1,...,9}{
      \draw[\mycolor, line width=0.1pt] (\x + \y:4) -- (\x + \y:25);
    }
  }
  \end{scope}

  % Draw the text
  \foreach \x in {0,10,...,50}{
    \draw[\mycolor, name intersections={of={\x} and border, by={first intersect}}] (first intersect) node[anchor=west] {\tiny $\x$°};
  }
  \foreach \x in {60,70,...,120}{
    \draw[\mycolor, name intersections={of={\x} and border, by={first intersect}}] (first intersect) node[anchor=south] {\tiny $\x$°};
  }
  \foreach \x in {130,140,...,230}{
    \draw[\mycolor, name intersections={of={\x} and border, by={first intersect}}] (first intersect) node[anchor=east] {\tiny $\x$°};
  }
  \foreach \x in {240,250,...,300}{
    \draw[\mycolor, name intersections={of={\x} and border, by={first intersect}}] (first intersect) node[anchor=north] {\tiny $\x$°};
  }
  \foreach \x in {310,320,...,350}{
    \draw[\mycolor, name intersections={of={\x} and border, by={first intersect}}] (first intersect) node[anchor=west] {\tiny $\x$°};
  }
}