# Problem of display in tikz

I want to draw a conic pendulum.

With this code :

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage{amsmath, amsthm, amssymb}
\usepackage[usenames,svgnames]{xcolor}
\usepackage{tikz-cd}
\usetikzlibrary{shapes,arrows,intersections}
\usetikzlibrary{matrix,fit,calc,trees,positioning,arrows,chains,shapes.geometric,shapes}

\begin{document}

\begin{tikzpicture}

\begin{scope}
\path[clip] (0,0) -- (0,3) -- (1,0.3);
\fill[blue!25!white, draw=blue!50!black] (0,3) circle (10mm);
\end{scope}

\draw(0.25,1.75) node[blue!50!black] {$\theta$};

\draw (0,3) node[above left]{$O$};
\draw[->] (0,0) -- (0,4) node[above]{$z$};
\draw[->] (0,3) -- (3,3) node[right]{$y$};
\draw[->] (0,3) -- (-1.5,1.8)node[below left]{$z$};

\draw (1,0.3) node{$\bullet$} node[right]{$M(m)$};
\draw[dashed] (0,3) -- (1,3.4);
\draw[dashed] (1,0.3) -- (1,3.4);
\draw (0.8,3.12) -- (0.8,3.32);
\draw (1,3.2) -- (0.8,3.12);

\draw[Aquamarine!50!black] (0,3) -- (1,0.3) node[midway, above right, Aquamarine!50!black]{$l$};
\draw[red, ->] (1,0.3) -- (1,-0.5) node[below]{$m\overrightarrow{g}$};
\draw[red, ->] (1,0.3) -- (0.75,0.975) node[left]{$\overrightarrow{T}$};

\begin{scope}
\path[clip] (-1.5,1.8) -- (0,3) -- (1,3.4);
\fill[Aquamarine!25!white, draw=Aquamarine!50!black] (0,3) circle (5mm);
\end{scope}

\end{tikzpicture}

\end{document}


I get this picture, which is close to what I want, but I want to mark the angle in the above horizontal plan, but as you can see it does not display correctly. Any idea why ? Do I have to declare explicit layers ? I tried without any success things with \pgfdeclarelayer

Note that I would be totally willing to change the way my angles are marked as it is the best I have found, but still do not find it very easy to use.

What I would like (beware my somewhat lacking skills in paint) :

EDIT : addition of the desired result

• Is it really that expensive to add the few lines that will make your code snippet a complete document? – gernot Oct 26 '16 at 14:21
• I may have misunderstood the question - which is the angle you want to highlight? (maybe a picture would make it absolutely clear) – Dai Bowen Oct 26 '16 at 14:31
• I added a figure – Anthony Martin Oct 26 '16 at 14:43
• Why not with angles library and use of pic angle – Salim Bou Oct 26 '16 at 14:59
• @Salim Out of curiosity, is it possible to get the 3D effect mentioned at the end of my answer using the angle pic? The obvious thing doesn't seem to work. – Emma Oct 26 '16 at 21:41

## 2 Answers

Your issue is that you are clipping to the triangle with the corners you specify, while the circle should extend outside that triangle. Even though you don't specify the third edge it is automatically inferred (as it would be if you were to fill that region). You can add another point to the clip path to fix it.

\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass[tikz]{standalone}
\begin{document}%
\begin{tikzpicture}
\begin{scope}
\path[clip] (0,0) -- (0,3) -- (1,0.3);
\fill[blue!25!white, draw=blue!50!black] (0,3) circle (10mm);
\end{scope}

\draw(0.25,1.75) node[blue!50!black] {$\theta$};

\draw (0,3) node[above left]{$O$};
\draw[->] (0,0) -- (0,4);
\draw[->] (0,3) -- (3,3);
\draw[->] (0,3) -- (-1.5,1.8);

\draw (1,0.3) node{$\bullet$} node[right]{$M(m)$};
\draw[dashed] (0,3) -- (1,3.4);
\draw[dashed] (1,0.3) -- (1,3.4);
\draw (0.8,3.12) -- (0.8,3.32);
\draw (1,3.2) -- (0.8,3.12);

\draw[Aquamarine!50!black] (0,3) -- (1,0.3) node[midway, above right, Aquamarine!50!black]{$l$};
\draw[red, ->] (1,0.3) -- (1,-0.5) node[below]{$m\overrightarrow{g}$};
\draw[red, ->] (1,0.3) -- (0.75,0.975) node[left]{$\overrightarrow{T}$};

\begin{scope}
\path[clip] (-1.5,1.8) -- (0,3) -- (1,3.4) -- (1,1.8);
\fill[Aquamarine!25!white, draw=Aquamarine!50!black] (0,3) circle (5mm);
\end{scope}

\end{tikzpicture}


Another option is to use the arc operation instead of drawing the full circle and clipping, but that would require you to know the angle. You could also use the angle pic, as described in Section 2.22 of the tikz manual.

On a somewhat unrelated note, it also looks like this is actually meant to be a 3D representation. You can use 3-dimensional coordinates in tikz and it will project them onto the paper (you can change the projection by setting options x=, y=, and z=, but the default is pretty good.) This also causes circles to be drawn automatically in the xy-plane, so you can draw circles (or right angles, etc.) in any plane you want by setting a scope. See drawing circles in a 3D plane.

For example, if the aquamarine angle is intended to be in the xz plane, you could use

\fill[Aquamarine!25!white, draw=Aquamarine!50!black] (0,3) [y={(0,0,1)}] circle (.5);


• I am a bit lost with your explanation : how can I need 4 points to define a triangle ? On the side note, you are implying that my whole figure coule have been far better by directly specifying 3D coordinates or am I reading too far in your answer ? Thanks anyway. – Anthony Martin Oct 26 '16 at 20:48
• The point is that you don't want to clip to the triangle, because the arc extends outside it. To see where you're clipping to with just the three points, try replacing the clip line with \draw[clip] \path[clip, orange] (-1.5,1.8) -- (0,3) -- (1,3.4) -- cycle; (adding cycle because tikz will clip to the closed region). This will outline the clipping region in orange. I've added a fourth point so that it doesn't cut through the middle of your arc. – Emma Oct 26 '16 at 20:59
• With regards to the side note, yes, if you are actually representing a figure in 3D then the whole figure could have been done more naturally by specifying 3D coordinates and letting tikz handle the projection. – Emma Oct 26 '16 at 21:01
• Gah, there was a typo in that first comment, but I don't seem to be able to edit it anymore: should have been just \draw[clip] (-1.5,1.8) -- (0,3) -- (1,3.4) -- cycle;, which will outline the clipping region in black. – Emma Oct 26 '16 at 21:09

So I misunderstood the desired angle from the original description (though I was right to say that the clipping path was wrong) and I Emma's answer covers everything the OP was after.

I think the issue is just the path you're cropping along just doesn't crop out the right parts. Using instead the path \path[clip] (1,3) -- (0,3) -- (1,3.4); I get what I believe is your desired angle.

\documentclass[a4paper]{article}

\PassOptionsToPackage{dvipsnames}{xcolor}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\begin{scope}
\path[clip] (0,0) -- (0,3) -- (1,0.3);
\fill[blue!25!white, draw=blue!50!black] (0,3) circle (10mm);
\end{scope}

\draw(0.25,1.75) node[blue!50!black] {$\theta$};

\draw (0,3) node[above left]{$O$};
\draw[->] (0,0) -- (0,4);
\draw[->] (0,3) -- (3,3);
\draw[->] (0,3) -- (-1.5,1.8);

\draw (1,0.3) node{$\bullet$} node[right]{$M(m)$};
\draw[dashed] (0,3) -- (1,3.4);
\draw[dashed] (1,0.3) -- (1,3.4);
\draw (0.8,3.12) -- (0.8,3.32);
\draw (1,3.2) -- (0.8,3.12);

\draw[Aquamarine!50!black] (0,3) -- (1,0.3) node[midway, above right, Aquamarine!50!black]{$l$};
\draw[red, ->] (1,0.3) -- (1,-0.5) node[below]{$m\overrightarrow{g}$};
\draw[red, ->] (1,0.3) -- (0.75,0.975) node[left]{$\overrightarrow{T}$};

\begin{scope}
\path[clip] (1,3) -- (0,3) -- (1,3.4);
\fill[Aquamarine!25!white, draw=Aquamarine!50!black] (0,3) circle (5mm);
\end{scope}

\end{tikzpicture}
\end{document}


So just to make this answer a bit more useful I thought I'd add a how I'd write this, defining a number of coordinates and then writing most of the sketch with respect to those coordinates.

\documentclass{article}
\PassOptionsToPackage{dvipsnames}{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}
\begin{tikzpicture}[scale=2]
\coordinate [label=below left:{$x$}] (xaxe) at (-1.5,1.8);
\coordinate [label=right:{$y$}] (yaxe) at (3,3);
\coordinate [label=above:{$z$}] (zaxe) at (0,4);
\coordinate (zmin) at (0,0);
\coordinate [label=above left:{$O$}] (origin) at (0,3);

\draw [->] (origin) -- (xaxe);
\draw [->] (origin) -- (yaxe);
\draw [->] (zmin) -- (zaxe);

\coordinate (m) at (1,0.3);

\begin{scope}
\path[name path global=thetaclip,clip] (zmin) -- (origin) -- (m) -- cycle;
\path[fill=blue!25!white, draw=blue!50!black, name path global=thetacirc] (origin) circle (10mm);
\end{scope}

\path [name intersections={of=thetacirc and thetaclip}] let
\p1 = ($($(intersection-1)!0.5!(intersection-2)$)-(origin)$),
\n1 = {veclen(\x1,\y1)},
\p2 = (35*\x1 / \n1, 35*\y1 / \n1)
in
(origin) -- ++(\p2) node {$\theta$};

\draw[dashed] (m) -- ($($(origin)!(m)!(yaxe)$)+(0,0.4)$) coordinate (abovem);
\draw[dashed] (origin) -- (abovem);
\draw (abovem) +(-0.2,-0.08) -- ++(-0.2,-0.28) -- ++(0.2,0.08);

\draw[Aquamarine!50!black] (origin) -- (m) node[midway, above right, Aquamarine!50!black]{$l$};
\draw[red, ->] (m) -- ++(0,-0.8) node[below]{$m\overrightarrow{g}$};
\draw[red, ->] (m) -- ($(m)!8mm!(origin)$) node[left]{$\overrightarrow{T}$};

\begin{scope}
\path[name path global=phiclip,clip] (xaxe) -- (origin) -- (abovem) -- (m) -- cycle;
\path[fill=Aquamarine!25!white, draw=Aquamarine!50!black,name path global=phicirc] (origin) circle (5mm);
\end{scope}

\path [name intersections={of=phicirc and phiclip}] let
\p1 = ($($(intersection-1)!0.5!(intersection-2)$)-(origin)$),
\n1 = {veclen(\x1,\y1)},
\p2 = (20*\x1 / \n1, 20*\y1 / \n1)
in
(origin) -- ++(\p2) node {$\phi$};

\node [label=right:{$M(m)$}] at (m) {$\bullet$};
\end{tikzpicture}
\end{document}


• This is not totally what I want, I can change my notations and subsequent calculus, but the ideal would be the figure I added. – Anthony Martin Oct 26 '16 at 14:39
• @Aerandal I think Emma's answer covers what you need along with some good suggestions but incase it's of interest I added a version of your code which uses relative instructions based on definitions of the most relevant nodes as well as some code which places the angle labels in the middle of the angle (although the distance still needs to be manually set). – Dai Bowen Oct 27 '16 at 23:54