# Labeling the lengths and angles in a diagram with measurements

I have a diagram that is to be used to define the sine, cosine, and tangent functions. How do I label the drawn radius "r"? How do I draw the angle for alpha? (I am trying to adapt the code that I have. There isn't a manual that explains the syntax.) Two line segments are to be drawn that are perpendicular to the x-axis. One of them is the line segment between the x-axis and the intersection P of the radius and the circle; the other is between the point (r,0) and the ray containing the drawn radius. (The lengths of these line segments are r\sin\alpha and r\tan\alpha.) How do I put a dot at the intersection Q of the second line segment and the ray containing the drawn radius? How do I draw a dotted line segment from P to Q?

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
%\usetikzlibrary{calc,angles,quotes}
\usepackage{pgfplots}

\begin{document}

\begin{center}
\begin{tikzpicture}[
dot/.style={
fill,
circle,
inner sep=2pt
}
]
\clip (-0.5,-0.5) rectangle (6,6);
\draw[<->] (-5,0) -- (5,0) node[below] {$x$};
\draw[<->] (0,-5) node (yaxis) {} -- (0,5) node[right] {$y$};
\node[dot,label={right:$(r\cos\alpha, \, r\sin\alpha)$}] at (3.464101615,2) {};
\draw (0,0) -- (3.464101615,2);
\draw[->] (1,0) +(0:1cm) [radius=1cm,start angle=0,end angle=30] node[midway,right]{$\alpha$};

\end{tikzpicture}
\end{center}

\end{document}

• TikZ and pgfplots manuals are by far the best manuals out there. – percusse Aug 11 '14 at 21:32

This is a possible solution. The point c are on the ray of radius found by the intersections skill from intersections library. Based on \tan \alpha expression, the 2nd line segment has length 1 on the x-axis which is inside the circle of radius 4.

Update Further automation is attempted where a macro \ang can be set between 0 and 90 degree, the intersections library will find the intersection points autmatically. The demonstration is for \ang=45.

1. How do I label the drawn radius "r"? use node[pos=xx, above=1pt] in the radius
2. Two line segments are to be drawn that are perpendicular to the x-axis. Use intersections of two curve/lines to find the intersection points b anc c.
3. How do I put a dot at the intersection of the second line segment and the ray containing the drawn radius? Use of \node[dot](<internal label>){};

Code

\documentclass[border=10pt]{standalone}%
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections}
\usepackage{pgfplots}
\def\ang{45}  % 0< \ang<90

\begin{document}

%\begin{center}
\begin{tikzpicture}[
dot/.style={
fill,
circle,
inner sep=2pt
}
]
\clip (-1,-1) rectangle (5.5,5.5);
\draw[dashed,fill=white,name path=curve] (0,0) coordinate(O){} circle [radius=4];
\draw[<->] (-5,0) -- (5,0) node[below] {$x$};
\draw[<->] (0,-5) node (yaxis) {} -- (0,5) node[right] {$y$};

\path[name path=lineb] (0,0) -- (\ang:5);
\draw[name intersections={of=curve and lineb, by={b}},thick]{};
\node[dot,label={left:$(r\cos\alpha, \, r\sin\alpha)$}] at (b) {};
\draw[->] (0,0) --node[pos=0.7,above]{$\alpha$} (0.8,0) arc (0:\ang:0.8cm) ;
\draw (O) --node[pos=0.7,above=1pt]{$r$} (b) -- (b |- O);

\path[name path=linec] (1,0) -- (1,3);
\draw[name intersections={of=lineb and linec, by={c}},thick]{};
\draw[] (c) --node[midway,right](){$\tan \alpha$} (c |- O);
\node[dot] at (c){};
\end{tikzpicture}
%\end{center}

\end{document}


Code

\documentclass[border=10pt]{standalone}%{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections}
\usepackage{pgfplots}

\begin{document}

%\begin{center}
\begin{tikzpicture}[
dot/.style={
fill,
circle,
inner sep=2pt
}
]
\clip (-0.5,-0.5) rectangle (7,7);
\draw[<->] (-5,0) -- (5,0) node[below] {$x$};
\draw[<->] (0,-5) node (yaxis) {} -- (0,5) node[right] {$y$};
\node[dot,label={left:$(r\cos\alpha, \, r\sin\alpha)$}] at (3.464101615,2) (a) {};
\draw (0,0) -- (3.464101615,2);
\draw[->] (0,0) --node[pos=0.7,above]{$\alpha$} (0.8,0) arc (0:30:0.8cm) ;
\draw (a) -- (a |- O);

% tan alpha

\draw[dashed,name path=linea] (O) -- (a);
\path[name path=linec] (1,0) -- (1,4);
\path[name intersections={of=linea and linec, by={c}},thick]{};
\draw[] (c) --node[midway,right](){$\tan \alpha$} (c |- O);
\node[dot] at (c){};
\end{tikzpicture}
%\end{center}

\end{document}

• Can you explain the syntax of the following commands? I did not find it in the TikZ manual. \path[name intersections={of=linea and linec, by={c}},thick]{}; and \draw[] (c) --node[midway,right](){$\tan \alpha$} (c |- O); I wanted one of the vertical line segments to be drawn at the tangent to the circle at (r,0). (So, the height should be r \tan \alpha.) I want the radius to be extended with a dotted line to the point that it intersects the second vertical line segment. Can you give me the code for this? – user143462 Aug 22 '14 at 16:36
• @user143462 -- Yes, my code actually can do rtanddrawing. In your case, it is r=4. So this is how you should change in my code. line 23 \path[name path=lineb] (0,0) -- (\ang:6); line 29 \path[name path=linec] (4,0) -- (4,6); lastly add a new line 34(last line) \draw[dashed](b)--(c); – Jesse Aug 22 '14 at 17:00
• In my code, curve=circle, lineb=radius, and linec=vertical tan line. name intersections={of=linea and linec, by{c}} means name the intersection of linea and linec by point c. The code will find its coordinate automatically. – Jesse Aug 22 '14 at 17:08