3

With tikz I can draw a circle in the following way:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=2cm/2]
  \newcommand\rad{1}
  \pgfplothandlerlineto
  \pgfplotfunction{\x}{-1, -0.99, ..., 1}{\pgfpointxy{\x}{sqrt(\rad*\rad-\x*\x)}}
  \pgfplotfunction{\x}{-1, -0.99, ..., 1}{\pgfpointxy{\x}{-sqrt(\rad*\rad-\x*\x)}}
  \pgfusepath{stroke}
\end{tikzpicture}
\end{document}

The output is:

enter image description here

I try to do the same thing using parametrisation:

\begin{tikzpicture}[x=2cm/2]
  \newcommand\rad{1}
  \pgfplothandlerlineto
  \pgfplotfunction{\alpha}{0, 0.01, ..., 6.28}{\pgfpointxy{\rad *cos(\alpha)}{\rad *sin(\alpha)}}
  \pgfusepath{stroke}
\end{tikzpicture}

How to draw a parametrised curve?

1 Answer 1

6

The \sin and \cos function expect their arguments in degrees, so if you change \pgfplotfunction{\alpha}{0, 0.01, ..., 6.28}... to \pgfplotfunction{\alpha}{0,5,10,...,360}... then all is well.

enter image description here

The full code:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
  \newcommand\rad{1}% better to define outside of environment

  \begin{tikzpicture}[x=2cm/2]
    \pgfplothandlerlineto
    \pgfplotfunction{\x}{-1, -0.99, ..., 1}{\pgfpointxy{\x}{sqrt(\rad*\rad-\x*\x)}}
    \pgfplotfunction{\x}{-1, -0.99, ..., 1}{\pgfpointxy{\x}{-sqrt(\rad*\rad-\x*\x)}}
    \pgfusepath{stroke}
  \end{tikzpicture}    
  \begin{tikzpicture}[x=2cm/2]
    \pgfplothandlerlineto
    \pgfplotfunction{\x}{0,5,10,...,360}{\pgfpointxy{\rad *cos(\x)}{\rad *sin(\x)}}
    \pgfusepath{stroke}
  \end{tikzpicture}

\end{document}

I have used \x rather than \alpha. Of course, using \alpha is fine but it hurts my sense of aesthetics :)

You must log in to answer this question.

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