Graphics, Figures & TablesPSTricks | Drawing polygon using relative coordinates

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

PSTricks | Drawing polygon using relative coordinates

Post by svend_tveskaeg »

Hi all.

First: My inspiration for trying the following is Herbert Voß' help in the thread PSTricks | Draw regular polygons on top of each other.

Now for a MWE:

Code: Select all

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

\begin{document}

\def\valueA{1 }
\def\valueB{\valueA 2 div }
\def\valueC{\valueA 2 5 sqrt 2 mul 5 add sqrt div mul }

\begin{figure}
 \centering
 \psset{unit=5}
  \begin{pspicture}(\valueA,\valueC)
   \pnode(0,0){A}
   \pnode(\valueA,0){B}
   \pnode(\valueB,\valueC){C}
   \pspolygon(A)(B)(C)
  \end{pspicture}
\end{figure}

\end{document}
What I try to do is define the constants

\valueA = 1
\valueB = \valueA / 2
\valueC = \valueA * (sqrt(5 + 2*sqrt(5)))/2

(but I am not familiar with RPN notation at all) and then draw a triangle with the corners (0,0), (\valueA,0), and (\valueB,\valueC). (Btw., this is a isosceles triangle with angles 72deg, 72deg, and 36deg.)

How do I do this?

Thank you in advance!
``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

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Drawing polygon using relative coordinates

Post by CrazyHorse »

svend_tveskaeg wrote: First: My inspiration for trying the following is Herbert Voß' help in the thread PSTricks | Draw regular polygons on top of each other.

[...]

What I try to do is define the constants

\valueA = 1
\valueB = \valueA / 2
\valueC = \valueA * (sqrt(5 + 2*sqrt(5)))/2

(but I am not familiar with RPN notation at all) and then draw a triangle with the corners (0,0), (\valueA,0), and (\valueB,\valueC). (Btw., this is a isosceles triangle with angles 72deg, 72deg, and 36deg.)
there are some limitations:

the pspicture environment uses the coordinates on TeX level to define the box which is used for typesetting, the reason why RPN notation is here not possible.

Code: Select all

(x,y)% coordinates without calculations for x,y
(r;phi) % polar coordinates without additional calculations
(! x y) % cartesian coordinates with possible calculations
Your example should be:

Code: Select all

  \begin{pspicture}(\valueA, \valueA)
   \pnode(0,0){A}
   \pnode(!\valueA 0){B}% also possible \pnode(\valueA,0){B}
   \pnode(!\valueB \valueC){C}% here we have extra calculations
   \pspolygon(A)(B)(C)
  \end{pspicture}
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Drawing polygon using relative coordinates

Post by svend_tveskaeg »

CrazyHorse wrote:

Code: Select all

(x,y)   % coordinates without calculations for x,y
(r;phi) % polar coordinates without additional calculations
(! x y) % cartesian coordinates with possible calculations
Great explanation! I definitely need to remember this!

Why should it be

Code: Select all

\begin{pspicture}(\valueA, \valueA)
and not

Code: Select all

\begin{pspicture}(\valueA, "some number greater than \valueA")
Since \valueC is greater than \valueA, I would guess that the height of the box would be too small then.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Drawing polygon using relative coordinates

Post by CrazyHorse »

svend_tveskaeg wrote:
CrazyHorse wrote:Why should it be

Code: Select all

\begin{pspicture}(\valueA, \valueA)
and not

Code: Select all

\begin{pspicture}(\valueA, "some number greater than \valueA")
Since \valueC is greater than \valueA, I would guess that the height of the box would be too small then.
The values have two meanings:

at first they define width and height of the TeX box

(-1,-2)(3,4) leads to a TeX box of 3-(-1)=4 units of width and 4-(-2)=6 units of height. The base line of the box is always on the current baseline ow the row.

at second the (-1,-2)(3,4) defines the internal position of the PostScript origin, which is inside the 4x6 TeX-box at 1 unit from the left and two units from bottom.

So far so good. You can mix values with and without a unit for the pspicture coordinates. If you want a value depending to another then use something like

Code: Select all

\newlength{foo}
\setlength\foo{4cm}
\begin{pspicture}(\foo,0)(1.5\foo,4cm)
Multiples of a length are allowed. For the other coordinates of the PSTricks macros you can use any of the combinations I told you.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Drawing polygon using relative coordinates

Post by svend_tveskaeg »

Awesome!

P.S. In the other post, I am trying to figure out how to draw a octagon+hexadecagon. (I will post my try/tries later.)
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply