Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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);.

share|improve this answer
    
Thanks Peter Grill. –  Regis da Silva Sep 12 '11 at 3:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.