11

How do I use the commands \pgfmathparse {tan (pi/3 r)} \pgfmathresult to draw the green line in the figure below?

\begin{tikzpicture}[>=latex,scale=2]
\draw circle (1);
\draw[->] (-1.2,0) -- (1.2,0) coordinate (x);
\draw[->] (0,-1.2) -- (0,1.2);

\fill[fill=green!25] (0,0) -- (.2,0) arc (0:60:.2) -- cycle;
\draw (0,0) -- (60:1);
\draw[<-,red,line width=1pt] (60:1) -- (60:1 |- x);
\draw (0,0) -- (60:2);
%tangent
\draw[<-,green,line width=1pt] (60:2) -- (1,0);
\end{tikzpicture}

enter image description here

1 Answer 1

15

Not exactly sure what you are asking or what is wrong with what you have, but here is how I would do it: Use \pgfmathsetmacro which invokes \pgfmathparse and uses the result from \pgfmathresult.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\newcommand*{\radius}{1}%
\pgfmathsetmacro{\YValue}{tan(deg(pi/3))*\radius}%
\begin{tikzpicture}[>=latex,scale=2]
\draw circle (1);
\draw[->] (-1.2,0) -- (1.2,0) coordinate (x);
\draw[->] (0,-1.2) -- (0,1.2);

\fill[fill=green!25] (0,0) -- (.2,0) arc (0:60:.2) -- cycle;
\draw[<-,red,line width=1pt] (60:1) -- (60:1 |- x);
\draw (0,0) -- (60:2);
%tangent
%\draw[<-,green,line width=1pt] (60:2) -- (1,0);
\draw[<-,green,line width=1pt] (1,\YValue) -- (1,0);
\end{tikzpicture}
\end{document}

I also removed the redundant \draw (0,0) -- (60:1); as that line gets overwritten by \draw (0,0) -- (60:2);.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .