4

Suppose I have two points the unit circle corresponding to 30 and 60 degrees from the x-axis.

I want to draw a line between these two points.

\documentclass[border=5mm]{standalone}

\usepackage{tikz}  
\usepackage{calculator}  
\usetikzlibrary{rulercompass}  
\usetikzlibrary{intersections,quotes,angles}  
\usetikzlibrary{calc}

\begin{document}  
\begin{tikzpicture}  
  \draw (\cos(30), \sin(30)) -- (\cos(60), \sin(60));  
\end{tikzpicture}
\end{document}

But this does not execute.

What is the correct way?

10

You're almost there. Two things to fix:

  1. \cos is a macro defined to typeset cos. To have PGF parse it as the cosine function you have to remove the backslash and let it parse the three letters c, o, s as the function name.

  2. When TikZ looks for coordinates it uses delimited macros, so when you do (cos(30), sin(30)) it will look for something between ( and the next ), which is cos(30, and things will go weird :). To avoid this you can "hide" the parentheses in braces: ({cos(30)}, {sin(30)}).

then it will work:

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usepackage{calculator}
\usetikzlibrary{rulercompass}
\usetikzlibrary{intersections,quotes,angles}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
  \draw ({cos(30)}, {sin(30)}) -- ({cos(60)}, {sin(60)});
\end{tikzpicture}
\end{document}
8

An addition, the question is already answered and explained by Phelype Oleinik.

TikZ also supports polar coordinates. Thus, the example can be reduced to

\documentclass[border=5mm, tikz]{standalone}
\begin{document}
  \tikz\draw (30:1) -- (60:1);
\end{document}

Result

3

A PSTricks solution just for fun!

\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\pspicture(-1,-1)(1,1)
\psline(1;30)(1;60)
\endpspicture
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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