8

I made a side view of a compass based on this answer symbols of pencil, ruler and compass

I'd like a view from above.

enter image description here

\documentclass[border=2pt]{standalone}

\usepackage{tikz,xparse}

\newcommand{\NodeAngle}[2]{%
    %\pgfextra{
        \pgfmathanglebetweenpoints%
            {\pgfpointanchor{#1}{center}}%
            {\pgfpointanchor{#2}{center}}%
            \global\let\MyAngle\pgfmathresult
    }%}

    % #1 premier point              ---- Distance entre 2 nodes ----
    % #2 second point
    % On récupère le résultat dans \MyDist
\makeatletter
\newcommand{\NodeDist}[2]{%
    \pgfpointdiff{\pgfpointanchor{#1}{center}}
                 {\pgfpointanchor{#2}{center}}
    % no need to use a new dimen
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    % to convert from pt to cm   
    \pgfmathparse{veclen(\pgf@xa,\pgf@ya)/28.45274}
    \global\let\MyDist\pgfmathresult % we need a global macro   
}
\makeatother

% ######################
%     Dessin crayon    #
% ######################

\newcommand{\Crayon}[1]{%
    \begin{scope}[scale=.7,#1]
    \fill[gray!60] (-.2,4.8) -- (.2,4.8)
                -- (.2,.8) --(.1,.65)
                -- (0,.8) -- (-.1,.66)
                -- (-.2,.8) -- cycle ;
    \draw[color=white] (0,4.8) -- (0,.8 );
    \fill[black] (-.2,4.3) -- (0,4.27)
                -- (.2,4.3) -- (.2,4.8) arc(30:150:0.23cm) ;
    \fill[brown!50] (-.2,.8)
        -- (0,0) node[coordinate,pos=0.75](a){}
        -- (.2,.8) node[coordinate,pos=0.25](b){}
        -- (.1,.65) -- (0,.8) -- (-.1,.66) -- cycle;
    \fill[gray] (a) -- (0,0) -- (b) -- cycle;
    \end{scope}
}



% ######################
%   Dessin du compas   #
% ######################

\NewDocumentCommand{\Compas}{smm}{%

    \IfBooleanTF{#1}{%
    % with *
    % keep distance between extemities
    }{%
    % without *
    % calulation of the distance between extemities
    \NodeDist{#2}{#3}
    }

    \NodeAngle{#2}{#3}

    \def\L{6} % taille des branches du compas

    % calcul de l'angle de l'ouverture
    \pgfmathsetmacro{\AngleCP}{asin(\MyDist/(2*\L))}

    \begin{scope}[shift=(#2)]
    \begin{scope}[%
        join=round,
        rotate=\MyAngle,
        shift=(270-\AngleCP:-\L)
        ]

    % branche pointe sèche
    \draw[rotate=-\AngleCP,fill=gray!80]
        (0,0)--(0,-\L)--(-.2,-\L+.8)--(-.2,0)--cycle ;
    \draw[rotate=-\AngleCP,fill=gray!05]
        (0,-\L+.8)--(0,-\L)--(-.2,-\L+.8)--cycle ;

    % branche crayon
    \draw[rotate=\AngleCP,fill=gray!80]
        (0,0)--(0,-\L)--(.2,-\L+.8)--(.2,0)--cycle ;

    \begin{scope}[rotate=\AngleCP,shift={(0,-\L)}]
    \Crayon{rotate=-12}
    \draw[fill=gray!25] (\L/30,\L/5) circle (\L/36) ;
    \fill[gray!5] (\L/30,\L/5)
            -- ++(30:\L/36) arc (30:45:\L/36) -- cycle ;
    \fill[gray!5] (\L/30,\L/5)
            -- ++(210:\L/36) arc (210:225:\L/36) ;
    \filldraw (\L/30,\L/5) circle (.02) ;
    \end{scope}

    % haut du compas
    \draw[fill=gray!80] (-.1,0) rectangle (.1,.7) ;
    \draw[fill=gray!25] (0,0) circle (.25) ;
    \fill[gray!5] (0,0) -- (30:.25) arc (30:45:.25) -- cycle ;
    \fill[gray!5,rotate=180] (0,0) -- (30:.25) arc (30:45:.25) -- cycle ;
    \filldraw (0,0) circle (.05) ;
    \end{scope}
    \end{scope}
}


\begin{document}

\begin{tikzpicture}

\coordinate (A) at (0,0) ;
\coordinate (B) at (3,2) ;

\Compas{A}{B}

\end{tikzpicture}

\end{document}
Tarass
  • 16,912
  • 3
    Here it is --> . – percusse Jul 11 '15 at 12:29
  • No ;-) at least - as it should be open ;-) – Tarass Jul 11 '15 at 12:32
  • 1
    I guess you mean a pair of compasses. When I first read the question, I thought you wanted a compass. And... er... why is this tagged 'contest'? It just seems to be a regular question. – cfr Jul 11 '15 at 12:37
  • Ok pair of compasse, I took compass from the other post, and I thought that in english like in french one says one compas. I will know now and correct my question. – Tarass Jul 11 '15 at 12:58
  • @JohnKormylo In Italian we call it "compasso". While your compass is "bussola". :D – Alenanno Jul 11 '15 at 21:40
  • @JohnKormylo I thought that was something else. According to OED, 'dividers' (plural) can mean either the kind of pair of compasses with a horizontal bar joining the legs, allowing them to be adjusted using a screw or a simple pair of compasses where both legs have metal points (i.e. no pencil). So I don't think what is pictured here would be dividers as far as OED is concerned, at least. – cfr Dec 25 '15 at 02:05
  • Incredible result! congratulations – Alain Matthes Mar 17 '16 at 15:43

2 Answers2

8

enter image description here

enter image description here

\documentclass[border=2pt]{standalone}

\usepackage{tikz,xparse}
\usetikzlibrary{calc}

\newcommand{\NodeAngle}[2]{%
    %\pgfextra{
        \pgfmathanglebetweenpoints%
            {\pgfpointanchor{#1}{center}}%
            {\pgfpointanchor{#2}{center}}%
            \global\let\MyAngle\pgfmathresult
    }%}

    % #1 premier point              ---- Distance entre 2 nodes ----
    % #2 second point
    % On récupère le résultat dans \MyDist
\makeatletter
\newcommand{\NodeDist}[2]{%
    \pgfpointdiff{\pgfpointanchor{#1}{center}}
                 {\pgfpointanchor{#2}{center}}
    % no need to use a new dimen
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    % to convert from pt to cm   
    \pgfmathparse{veclen(\pgf@xa,\pgf@ya)/28.45274}
    \global\let\MyDist\pgfmathresult % we need a global macro   
}
\makeatother

% ######################
%     Dessin crayon    #
% ######################

\newcommand{\Crayon}[1]{%
    \begin{scope}[scale=.7,#1]
    % Dessin de bois
    \fill[gray!60] (-.2,4.8) -- (.2,4.8)
                -- (.2,.8) --(.1,.65)
                -- (0,.8) -- (-.1,.66)
                -- (-.2,.8) -- cycle ;
    \draw[color=white] (0,4.8) -- (0,.8 );
    \fill[black] (-.2,4.3) -- (0,4.27)
                -- (.2,4.3) -- (.2,4.8) arc(30:150:0.23cm) ;

    % pointe taillée
    \fill[brown!50] (-.2,.8)
        -- (0,0) node[coordinate,pos=0.75](a){}
        -- (.2,.8) node[coordinate,pos=0.25](b){}
        -- (.1,.65) -- (0,.8) -- (-.1,.66) -- cycle;
    \fill[gray] (a) -- (0,0) -- (b) -- cycle;
    \end{scope}
}

\newcommand{\PointeCr}[1]{% pour le compas vu de haut
    \begin{scope}[scale=.7,#1]
    % pointe taillée
    \fill[brown!50] (-.2,.8)
        -- (0,0) node[coordinate,pos=0.75](a){}
        -- (.2,.8) node[coordinate,pos=0.25](b){}
        -- (.1,.65) -- (0,.8) -- (-.1,.66) -- cycle;
    \fill[gray] (a) -- (0,0) -- (b) -- cycle;
    \end{scope}
}


% ######################
%   Dessin du compas   #
% ######################

\NewDocumentCommand{\Compas}{smm}{%

    \IfBooleanTF{#1}{%
    % with *
    % keep distance between extemities
    }{%
    % without *
    % calulation of the distance between extremities
    \NodeDist{#2}{#3}
    }

    \NodeAngle{#2}{#3}

    \def\L{6} % taille des branches du compas

    % calcul de l'angle de l'ouverture
    \pgfmathsetmacro{\AngleCP}{asin(\MyDist/(2*\L))}

    \begin{scope}[shift=(#2)]
    \begin{scope}[%
        join=round,
        rotate=\MyAngle,
        shift=(270-\AngleCP:-\L)
        ]

    % branche pointe sèche
    \draw[rotate=-\AngleCP,fill=gray!80]
        (0,0)--(0,-\L)--(-.2,-\L+.8)--(-.2,0)--cycle ;
    \draw[rotate=-\AngleCP,fill=gray!05]
        (0,-\L+.8)--(0,-\L)--(-.2,-\L+.8)--cycle ;

    % branche crayon
    \draw[rotate=\AngleCP,fill=gray!80]
        (0,0)--(0,-\L)--(.2,-\L+.8)--(.2,0)--cycle ;

    \begin{scope}[rotate=\AngleCP,shift={(0,-\L)}]
    \Crayon{rotate=-12}
    \draw[fill=gray!25] (\L/30,\L/5) circle (\L/36) ;
    \fill[gray!5] (\L/30,\L/5)
            -- ++(30:\L/36) arc (30:45:\L/36) -- cycle ;
    \fill[gray!5] (\L/30,\L/5)
            -- ++(210:\L/36) arc (210:225:\L/36) ;
    \filldraw (\L/30,\L/5) circle (.02) ;
    \end{scope}

    % haut du compas
    \draw[fill=gray!80] (-.1,0) rectangle (.1,.7) ;
    \draw[fill=gray!25] (0,0) circle (.25) ;
    \fill[gray!5] (0,0) -- (30:.25) arc (30:45:.25) -- cycle ;
    \fill[gray!5,rotate=180]
        (0,0) -- (30:.25) arc (30:45:.25) -- cycle ;
    \filldraw (0,0) circle (.05) ;
    \end{scope}
    \end{scope}
}


\NewDocumentCommand{\CompasH}{smm}{%

    \IfBooleanTF{#1}{%
    % with *
    % keep distance between extemities
    }{%
    % without *
    % calulation of the distance between extremities
    \NodeDist{#2}{#3}
    }

    \NodeAngle{#2}{#3}

\def\L{6} 
\pgfmathsetmacro{\Scale}{\MyDist/2/\L}

\begin{scope}[%
    join=round,
    shift=($(#2)!.5!(#3)$),
    rotate=\MyAngle]

\begin{scope}[xscale=\Scale]
    % branche pointe sèche
    \draw[rotate=-90,fill=gray!80]
        (.1,\L-1) rectangle (-.1,-\L+1) ;
    \draw[rotate=-90,fill=gray!05]
        (.1,-\L+1)--(0,-\L)--(-.1,-\L+1)--cycle ;
\end{scope}

\draw[fill=gray!25,rounded corners=2pt]
    (-.4,-.14) rectangle(.4,.14) ;

\draw[fill=gray!25,rounded corners=2pt]
    (-.3,-.14) rectangle(.3,.14) ;

\begin{scope}[xscale=\Scale]

    \begin{scope}[shift={(\L,0)}]
        \clip (-1.4,-.17) rectangle (-12,.17) ;
        \Crayon{rotate=90,yscale=1.2}
    \end{scope}

    \begin{scope}[shift={(\L,0)}]
        \clip (-1.4,-.17) rectangle (0.1,.17) ;
        \Crayon{rotate=90,yscale=2}
    \end{scope}

    \draw[draw=gray!50,
        ultra thin,
        fill=gray!15,
        rounded corners=2pt]
        (4.25,-.17) rectangle (4.85,.17) ;

    \draw[ultra thick,
        yshift=-.5pt,
        black!80,
        line cap=round]
        (4.35,-.17)--(4.75,-.17) ;
\end{scope}

    \filldraw[gray!50!black] (0,0) circle (.08) ;
    \fill[black] (0,0) circle (.2pt) ;

\end{scope}

}

\begin{document}

\begin{tikzpicture}
\coordinate (A) at (0,0) ;
\coordinate (B) at (2,0) ;

\Compas{A}{B}
\CompasH{A}{B}

\end{tikzpicture}

\end{document}
Tarass
  • 16,912
  • If you could put all of this inside of a pic it would be perfect. – Manuel Jul 26 '15 at 22:08
  • For a pic, I think it has to be reexamined from scratch because of the use of macro for length and angles. And if that, add an optical effect that displays top bigger than extremities – Tarass Jul 27 '15 at 05:14
4

You could add this fragment to your current MWE, but to look realistic you will have to start from scratch and draw a 3D compass.

\begin{tikzpicture}

    \coordinate (A) at (0,0) ;
    \coordinate (B) at (3,0) ;

    \pgfmathparse{cos(80)}% foreshorten image by 80 degrees
    \let\temp=\pgfmathresult% and don't own a decent calculator

    \begin{scope}[yscale=\temp]
    \Compas{A}{B}
    \end{scope}

    \end{tikzpicture}

I started working on a 3d compass, but only got this far. It turns out that drawing circles in 3d can get complicated.

\documentclass[border=2pt]{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,arrows.meta}
\usepackage{tikz-3dplot}

\begin{document}
\Large
\tdplotsetmaincoords{60}{30}
\begin{tikzpicture}[scale=1in,tdplot_main_coords]
\draw[thick] (0,0,0) circle (.1);
\draw[thick,-latex] (0,0,0) -- (.1,0,0) node[right] {x}
 (0,0,0) -- (0,.1,0) node[right] {y}
 (0,0,0) -- (0,0,.1) node[right] {z};
\tdplotsetrotatedcoords{0}{90}{0}
\begin{scope}[tdplot_rotated_coords]
\draw[red,thick] (0,0,0) circle (.1);
\draw[red,thick,-latex] (0,0,0) -- (.1,0,0) node[above] {x}
 (0,0,0) -- (0,.1,0) node[above] {y}
 (0,0,0) -- (0,0,.1) node[above] {z};
\end{scope}
\tdplotsetrotatedcoords{90}{90}{-90}
\begin{scope}[tdplot_rotated_coords]
\draw[green,thick] (0,0,0) circle (.1);
\draw[green,thick,-latex] (0,0,0) -- (.1,0,0) node[left] {x}
 (0,0,0) -- (0,.1,0) node[left] {y}
 (0,0,0) -- (0,0,.1) node[left] {z};
\end{scope}
\begin{scope}[tdplot_screen_coords]
\draw[thick,blue] (0,0) circle (.1);
\end{scope}
\end{tikzpicture}

\end{document}

drawing circles

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • I already thought about that, and the good place for that is in the second nested scope. I use yscale=-1 to draw the compasses in the way. In fact I need a very stylized view from above during the rotation of the compasses. I have asked in case of a graphist has a few moment to spare. – Tarass Jul 11 '15 at 17:34
  • It looks good.. – Tarass Jul 12 '15 at 13:48
  • The screw looks fantastic! – Gonzalo Medina Jul 17 '15 at 01:45