Tuesday, March 27, 2012

Plot in polar coordinate --- polarplot

With the option "polarplot=true", it is possible to use command "\psplot" to create a polar plot. The syntax is the same as usual --- "\psplot[polarplot=true,...]{x0}{x1}{function}" where "x0" and "x1" are the start and end angle. "function" is interpreted as a function r=f(theta) in the polar plotting. So if a circle with radius 1 is to be plotted, command "\psplot[polarplot=true]{0}{360}{1}" can be used.
Now we come to draw a cardioid. The function of a cardioid in polar coordinate reads "r=a(1+sin(x))". And we take a=1.5.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
  \psset{plotpoints=500}
  \begin{psgraph}{->}(0,0)(-0.5,-2)(3.5,2.5){5cm}{5cm}
    \psplot[polarplot=true]{0}{360}
      {x cos 1 add 1.5 mul}
  \end{psgraph}
\end{document}

Fig.1 Plot in polar coordinate --- cardioid.

The axesstyle can also be set to polar. The only thing need to do is setting "axesstyle=polar". This time we use a three-leaved rose curve (r=a*sin(3x),a=3.5) to shown it.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
\psset{plotpoints=500}
\begin{pspicture}(-4,-4)(4,4)
  \psaxes[axesstyle=polar,xAxisLabel=some,
    subticks=2,tickcolor=red,tickwidth=1pt,
    subtickcolor=green]{->}(0,0)(-4,4)(4,4)
  \psplot[polarplot=true,linewidth=2pt,
    linecolor=blue]{0}{360}
    {3 x mul sin 3.5 mul}
\end{pspicture}
\end{document}

Fig.2 Plot in polar coordinate — three leaved rose curve.
 
Files Download: tex ps pdf 

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.