Graphics, Figures & Tablespst-poly | Center and Radius of Polygon

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-poly | Center and Radius of Polygon

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pst-poly}

\begin{document}

\begin{figure}
\def\radius{3 }
 \centering
  \begin{pspicture}(6,6)
   \pscircle(!\radius \radius){\radius}
   \PstPentagon[PolyNbSides=6]
  \end{pspicture}
\end{figure}

\end{document}
How do I specify the center and the radius of the hexagon? (I have had a look at the pst-poly documentation but that did not help me.)

Thank you in advance!

P.S. I am trying to draw the figure that is produced by compiling the following (not very elegant) code:

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calculate
  \fp_eval:n
\ExplSyntaxOff

\begin{document}

\begin{figure}
\def\radius{3.5 }
\def\maksimum{\calculate{2*\radius} }
 \centering
  \begin{pspicture}(\maksimum,\maksimum)
   \pnode(!\radius \radius){X}
   \pscircle(X){\radius}
   \pnode(!2 \radius mul \radius){A}
   \pnode(!3 2 div \radius mul 2 3 sqrt add 2 div \radius mul){B}
   \pnode(!1 2 div \radius mul 2 3 sqrt add 2 div \radius mul){C}
   \pnode(!0 \radius){D}
   \pnode(!1 2 div \radius mul 2 3 sqrt sub 2 div \radius mul){E}
   \pnode(!3 2 div \radius mul 2 3 sqrt sub 2 div \radius mul){F}
   \pspolygon(A)(B)(C)(D)(E)(F)
  \psset{linestyle=dotted,nrot=:U}
   \pcline(A)(D)
   \pcline(B)(E)
   \pcline(C)(F)
   \pcline[offset=7pt,linecolor=white](X)(B)
   \ncput*{\footnotesize{$r = \SI{\radius}{\cm}$}}
  \end{pspicture}
\end{figure}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pst-poly | Center and Radius of Polygon

Post by localghost »

svend_tveskaeg wrote:[…] (I have had a look at the pst-poly documentation but that did not help me.) […]
Hard to believe since the manual is full of examples.

If you want to draw a hexagon, you should not use \PstPentagon but \PstHexagon instead. Furthermore you can specify the unit scale for every single command.

Code: Select all

\documentclass{standalone}
\usepackage{pst-poly,pstricks-add}
\usepackage{auto-pst-pdf}

\begin{document}
  \def\radius{3 }
  \begin{pspicture}[showgrid=false](6,6)
    \pscircle(!\radius \radius){\radius}
    \PstHexagon[unit=\radius]
  \end{pspicture}
\end{document}
The hexagon (or a polygon in general, respectively) is by default not drawn regularly around the coordinate origin. You have to add the PstPicture=false option (or do this globally by \psset).


Thorsten
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-poly | Center and Radius of Polygon

Post by svend_tveskaeg »

localghost wrote:
svend_tveskaeg wrote:[…] (I have had a look at the pst-poly documentation but that did not help me.) […]
Hard to believe since the manual is full of examples.
Hmm... Would you please direct me to the page where the center of the \PstHexagon is specified? (I do not always want the circle to be indside a box going from (0,0) to (2r,2r) where r is the radius.)
localghost wrote: If you want to draw a hexagon, you should not use \PstPentagon but \PstHexagon instead. Furthermore you can specify the unit scale for every single command.
Great. Thank you!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pst-poly | Center and Radius of Polygon

Post by localghost »

svend_tveskaeg wrote:[…] Would you please direct me to the page where the center of the \PstHexagon is specified? […]
Take a look at the example of the perspective model on page 7 of the pst-poly manual. You can place every kind of polygon arbitrarily by the \rput command.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-poly | Center and Radius of Polygon

Post by svend_tveskaeg »

Thank you, Thorsten!

I tried to make to drawing as `automatic' as possible, so I had a look at the first example at page 30 in the pstricks-add manual. Here is what I came up with

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pst-poly,pstricks-add}
\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calculate
  \fp_eval:n
\ExplSyntaxOff

\begin{document}

\begin{figure}
\def\NumSides{8 }
\def\Radius{3.5 }
\def\Maximum{\calculate{2*\Radius} }
\def\RelAngle{\calculate{360/\NumSides} }
 \centering
  \begin{pspicture}[showgrid=false](\Maximum,\Maximum)
   \pnode(!\Radius \Radius){A}
   \pnode(!2 \Radius mul \Radius){B}
   \pcline[offset=6pt,linecolor=white](A)(B)
   \ncput*{\footnotesize{$r = \SI{\Radius}{\cm}$}}
   \pscircle(A){\Radius}
   \PstPolygon[PolyNbSides=\NumSides,unit=\Radius]
   \multido{\r=0+\RelAngle}{\NumSides}{\psRelLine[angle=\r,linestyle=dotted](A)(B){1}{C}}
  \end{pspicture}
\end{figure}

\end{document}
This is almost as I want it, but when

gcd(\NumSides, 360) = 1

there is a problem. The dotted lines do not exactly intersect with the vertices of the regular polygon and a numerical value of

"some integer"/\NumSides

is printed next to the figure. (I think that \RelAngle is rounded to an integer, which is a problem, but I am fare from sure that this is the problem.)

How do I solve this?

Thank you in advance!

Update:
I found the problem. In \multido it must (of course) be \rA instead of \iA., i.e., the complete code is

Code: Select all

\documentclass{article}

\usepackage{auto-pst-pdf,pst-poly,pstricks-add}
\usepackage[locale=DE]{siunitx}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calculate
  \fp_eval:n
\ExplSyntaxOff

\begin{document}

\begin{figure}
\def\NumSides{6 }
\def\Radius{3.5 }
\def\Maximum{\calculate{2*\Radius} }
\def\RelAngle{\calculate{360/\NumSides} }
 \centering
  \begin{pspicture}[showgrid=false](\Maximum,\Maximum)
   \pnode(!\Radius \Radius){A}
   \pnode(!2 \Radius mul \Radius){B}
   \pcline[offset=6pt,linecolor=white](A)(B)
   \ncput*{\small{$r = \SI{\Radius}{\centi\metre}$}}
   \pscircle(A){\Radius}
   \PstPolygon[PolyNbSides=\NumSides,unit=\Radius]
   \multido{\r=0+\RelAngle}{\NumSides}{%
     \psRelLine[angle=\r,linestyle=dotted](A)(B){1}{C}
   }
  \end{pspicture}
\end{figure}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply