# How to draw this diagram with minimum effort?

I want to save my time by avoiding manual calculation if possible. Could you help me to simplify the following code snippet?

\documentclass{minimal}
\usepackage{pst-node}
\psset{unit=6.2cm,linewidth=1.6pt}
\pagestyle{empty}
\begin{document}
\begin{pspicture}[showgrid=false](-0.1,-0.1)(2,2.1)
\SpecialCoor
\pstVerb{/side 1 def}
\pnode(!0 side){A}\uput[180](A){$A$}
\pnode(!0 0){B}\uput[225](B){$B$}
\pnode(!80 sin 2 exp side mul 40 sin div 70 sin div 0){C}\uput[-45](C){$C$}
\pnode(!80 sin side mul 30 sin div 20 cos mul 80 sin side mul 30 sin div 20 sin mul){D}\uput[0](D){$D$}
\pnode(!50 sin side mul 20 sin div 60 cos mul 50 sin side mul 20 sin div 60 sin mul){E}\uput[90](E){$E$}
\pnode(!80 sin side mul 70 sin div 60 cos mul 80 sin side mul 70 sin div 60 sin mul){P}\uput[110](P){$P$}
\pnode(!80 sin 2 exp side mul 60 sin div 70 sin div 20 cos mul 80 sin 2 exp side mul 60 sin div 70 sin div 20 sin mul){Q}\uput[80](Q){$Q$}
\pspolygon(A)(B)(C)(D)(E)
\psset{linecolor=red}
\psline(A)(D)
\psline(B)(E)
\psset{linecolor=blue}
\psline(P)(C)
\psline(B)(D)
\psset{linecolor=magenta,linewidth=0.8pt,arcsep=1.6pt,arrows=<->}
\psarc[origin={A}](A){30pt}{(D)}{(E)}\uput{15pt}[15](A){$\theta$}

\psarc[origin={B}](B){45pt}{(E)}{(A)}\uput{25pt}[75](B){$30^\circ$}
\psarc[origin={B}](B){45pt}{(C)}{(D)}\uput{25pt}[10](B){$20^\circ$}
\psarc[origin={B}](B){45pt}{(D)}{(E)}\uput{25pt}[40](B){$\alpha$}

\psarc[origin={D}](D){40pt}{(A)}{(B)}\uput{15pt}[187.5](D){$30^\circ$}
\psarc[origin={D}](D){40pt}{(B)}{(C)}\uput{15pt}[235](D){$50^\circ$}
\psarc[origin={D}](D){40pt}{(E)}{(A)}\uput{15pt}[140](D){$50^\circ$}

\psarc[origin={C}](C){35pt}{(D)}{(P)}\uput{15pt}[100](C){$70^\circ$}
\psarc[origin={C}](C){35pt}{(P)}{(B)}\uput{13pt}[160](C){$40^\circ$}

\psarc[origin={P}](P){45pt}{(C)}{(D)}\uput{20pt}[-25](P){$30^\circ$}
\end{pspicture}
\end{document}


For those who are interested in knowing the solution of this geometry problem, see A tricky geometry problem.

• I would draw it using TikZ which provides a nice syntax (once you understood it), allows you to use polar coordinates and has a library to calculate intersections for you. However, if you have to construct the diagram only from the shown values, things are a little bit more complicated. – Martin Scharrer Jul 4 '11 at 5:38
• It would be interesting to know what are the points to start the construction. I made a similar picture with a similar problem with tkz-euclide. With TikZ it's not very easy to draw an arc with arrows if you don't know the angle ! It's a question I would like to ask ! – Alain Matthes Jul 4 '11 at 6:23
• I would use GeoGebra. – Leo Liu Jul 4 '11 at 6:31
• Friendly Ghost It's the problem !! I would like to know the points given in the question !! – Alain Matthes Jul 4 '11 at 6:40

For the intersection points use \psIntersectionPoint. Here is a solution without a calculated point, but with the angles alpha and theta:

\documentclass{minimal}
\psset{unit=6.2cm,linewidth=1.6pt}
\pagestyle{empty}
\def\psArc(#1)#2(#3)(#4)#5[#6]#7{%
\psarc[origin={#1}](#1){#2}{(#3)}{(#4)}\uput{#5}[#6](#1){$#7$}}
\def\Uput[#1](#2){\uput[#1](#2){$#2$}}
\begin{document}

\begin{pspicture}(-0.1,-0.1)(2,2.1)
\pnode(0,1){A}\Uput[180](A) \pnode{B}\Uput[225](B)
\rput(A){\pnode(3;40){E'}} \pnode(3;60){E''}
\psIntersectionPoint(A)(E')(B)(E''){E}\Uput[90](E)
\rput(A){\pnode(3;-10){D'}} \rput(E){\pnode(3;-60){D''}}
\psIntersectionPoint(A)(D')(E)(D''){D}\Uput[0](D)
\pnode(3;0){C'} \rput(D){\pnode(3;-110){C''}}
\psIntersectionPoint(B)(C')(D)(C''){C}\Uput[-45](C)
\psIntersectionPoint(A)(D)(B)(E){P} \Uput[110](P)
\psIntersectionPoint(B)(D)(C)(P){Q} \Uput[80](Q)

\pspolygon(A)(B)(C)(D)(E)
\psset{linecolor=red}
\psline(A)(D)\psline(B)(E)
\psset{linecolor=blue}
\psline(P)(C)\psline(B)(D)
\psset{linecolor=magenta,linewidth=0.8pt,arcsep=1.6pt,arrows=<->}
\psArc(A){30pt}(D)(E){15pt}[15]{\theta}
\psArc(B){45pt}(E)(A){25pt}[75]{30^\circ}
\psArc(B){45pt}(C)(D){25pt}[10]{20^\circ}
\psArc(B){45pt}(D)(E){25pt}[40]{\alpha}
\psArc(D){40pt}(A)(B){15pt}[187.5]{30^\circ}
\psArc(D){40pt}(B)(C){15pt}[235]{50^\circ}
\psArc(D){40pt}(E)(A){15pt}[140]{50^\circ}
\psArc(C){35pt}(D)(P){15pt}[100]{70^\circ}
\psArc(C){35pt}(P)(B){13pt}[160]{40^\circ}
\psArc(P){45pt}(C)(D){20pt}[-25]{30^\circ}
\psline[linestyle=dashed](E)(Q)
\end{pspicture}

\end{document}


• I had to think about it, but I suppose it should be possible. – user2478 Jul 4 '11 at 7:44
• Does pst-euclid make it easier? – Friendly Ghost Jul 4 '11 at 12:07
• not in this special case where the points are unknown. In general it is the better tool for euclidian graphics – user2478 Jul 4 '11 at 12:09
• @Friendly Ghost: If you can use your calculated angles alpha and theta then it is no problem, see edited answer – user2478 Jul 4 '11 at 12:45
• I am heavily using TikZ but I keep reading your pstricks codes with awe. Sense and simplicity :P – percusse Nov 24 '11 at 2:19

I guess it might be useful to show how this can be accomplished with TikZ. As Altermundus noted in the comments, drawing a double tipped arrow to mark an angle is difficult (if no arrow tips were needed, a clip would suffice). I've used a macro here that takes three nodes as arguments and uses pgfmath to calculate the angles and draw the arrows. This is not terribly precise, but should be good enough for many applications.

A second interesting bit is the calc expression for coordinate transformations: The syntax ($(A)!0.5!30:(B)$) rotates a point at the position 0.5 on the line from A to B by 30 degrees around A.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\begin{document}

% Command for adding angle labels
\newcommand{\anglebetween}[4]{
\pgfpointanchor{#1}{center}
\pgfgetlastxy{\xA}{\yA}
\pgfpointanchor{#2}{center}
\pgfgetlastxy{\xB}{\yB}
\pgfpointanchor{#3}{center}
\pgfgetlastxy{\xC}{\yC}
\pgfmathtruncatemacro\startangle{round( atan2((\xC-\xB),(\yC-\yB)) )}
\pgfmathtruncatemacro\deltaangle{round(
ifthenelse((atan2((\xA-\xB),(\yA-\yB))-atan2((\xC-\xB),(\yC-\yB)))>0,
atan2((\xA-\xB),(\yA-\yB))-atan2((\xC-\xB),(\yC-\yB)),
360+atan2((\xA-\xB),(\yA-\yB))-atan2((\xC-\xB),(\yC-\yB))
)}
\draw [latex-latex] ($(#2)!0.2*\baselength!(#3)$) arc [radius=0.2*\baselength,start angle=\startangle, delta angle=\deltaangle];
\node at ($(#2)!0.16*\baselength!0.5*\deltaangle:(#3)$) {#4};
}

% Wrapper if angle is given
\newcommand{\labelknownangle}[3]{
\anglebetween{#1}{#2}{#3}{\deltaangle$^{\circ}$}
}

% Wrapper if angle unknown
\newcommand{\labelunknownangle}[4]{
\anglebetween{#1}{#2}{#3}{#4}
}

% Define length of first line
\def\baselength{7cm}
% Define length of "rays" used for finding intersections
\def\raylength{3*\baselength}

\begin{tikzpicture}

% Start of the code for the actual picture
\path (0,0) coordinate (B) -- +(\baselength,0) coordinate (C);

\path [name path=BD] (B) -- +(20:\raylength);
\path [name path=CD] (C) -- +(70:\raylength);
\path [name intersections={of=BD and CD, by=D}];

\path [name path=CP] (C) -- +(140:\raylength);
\path [name path=AD] (D) -- +(170:\raylength);
\path [name intersections={of=CP and AD, by=P}];

\path [name path=BE] (B) -- ($(B)!3!(P)$);
\path [name path=DE] (D) -- +(120:\raylength);
\path [name intersections={of=BE and DE, by=E}];

\path [name path=AB] (B) -- ($(B)!3!30:(E)$);
\path [name path=AD] (D) -- ($(D)!3!(P)$);
\path [name intersections={of=AB and AD, by=A}];

% Reset bounding box so the "rays" don't enlarge the picture
\pgfresetboundingbox
\draw (A) node [left] {A}
-- (B) node [below left] {B}
-- (C) node [below right] {C}
-- (D) node [right] {D}
-- (E) node [above] {E}
-- cycle
;

\draw [red] (B) -- (E)
(A) -- (D)
;

\draw [blue] (B) -- (D)
(C) -- (P) node [above,black] {P}
;

\labelknownangle{D}{B}{C}
\labelknownangle{A}{B}{P}
\labelknownangle{B}{C}{P}
\labelknownangle{P}{C}{D}
\labelknownangle{C}{D}{B}
\labelknownangle{B}{D}{A}
\labelknownangle{A}{D}{E}
\labelknownangle{D}{P}{C}
\labelunknownangle{E}{B}{D}{$\alpha$}
\labelunknownangle{E}{A}{D}{$\theta$}
\end{tikzpicture}
\end{document}

• @jake Nice and interesting because when I wrote tkz-euclide , atan2 did not exist in pgfmath. Now it's useful tu use it ! – Alain Matthes Jul 4 '11 at 13:35

A solution with tkz-euclide

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-euclide}
\usetkzobj{all}

\definecolor{fondpaille}{cmyk}{0,0,0.1,0}
\pagecolor{fondpaille}
\color{Maroon}
\tkzSetUpColors[background=fondpaille,text=Maroon]
\begin{document}
\begin{tikzpicture}[scale=1]
\tkzInit[ymin=-1,ymax=12,xmin=-1,xmax=10]
\tkzClip
\tkzDefPoint(1,0){B}  \tkzDefPoint(8,0){C}
%To draw a triangle with two angles, I use two rotations
\tkzDefPointBy[rotation= center B angle 20](C)    \tkzGetPoint{i}
\tkzDefPointBy[rotation= center C angle -110](B) % trick no need to name
% the result
\tkzInterLL(B,i)(C,tkzPointResult)                \tkzGetPoint{D}
% idem for  P
\tkzDefPointBy[rotation= center D angle -80](C)   \tkzGetPoint{i}
\tkzDefPointBy[rotation= center C angle -40](B)
\tkzInterLL(D,i)(C,tkzPointResult)                \tkzGetPoint{P}
\tkzDefPointBy[rotation= center D angle -50](P)
\tkzInterLL(D,tkzPointResult)(B,P)                \tkzGetPoint{E}
\tkzDefPointBy[rotation= center B angle 30](P)
\tkzInterLL(B,tkzPointResult)(D,P)                \tkzGetPoint{A}
% now we get the point Q
\tkzInterLL(B,D)(C,P)                             \tkzGetPoint{Q}

% Now drawing and labeling

\tkzDrawPolygon(A,B,C,D,E)
\tkzDrawSegments[red](A,D B,E)
\tkzDrawSegments[blue](B,D C,P)
\tkzDrawPoints(A,B,C,D,E,P,Q)

\tkzMarkAngle[arc=ll,size=1 cm,color=red](P,B,A)
\tkzLabelAngle[pos=.8](P,B,A){\tiny$30^{\circ}$}
\tkzMarkAngle[arc=ll,size=1 cm,color=red](Q,P,D)
\tkzLabelAngle[pos=.8](Q,P,D){\tiny$30^{\circ}$}
\tkzMarkAngle[arc=ll,size=1 cm,color=red](P,D,Q)
\tkzLabelAngle[pos=-.8](P,D,Q){\tiny$30^{\circ}$}
\tkzMarkAngle[arc=l,size=1 cm](C,B,D)
\tkzLabelAngle[pos=.8](C,B,D){\tiny$20^{\circ}$}
\tkzMarkAngle[arc=l,size=1 cm](Q,C,B)
\tkzLabelAngle[pos=.8](Q,C,B){\tiny$40^{\circ}$}
\tkzMarkAngle[arc=l,size=1 cm](B,D,C)
\tkzLabelAngle[pos=.8](B,D,C){\tiny$50^{\circ}$}
\tkzMarkAngle[arc=l,size=1 cm](D,C,P)
\tkzLabelAngle[pos=.8](D,C,P){\tiny$70^{\circ}$}
\tkzMarkAngle[arc=l,size=1 cm](E,D,P)
\tkzLabelAngle[pos=.8](E,D,P){\tiny$50^{\circ}$}
\tkzMarkAngle[arc=l,size=1 cm,color=blue](D,B,P)
\tkzLabelAngle[pos=.8](D,B,P){\tiny$\alpha$}
\tkzMarkAngle[arc=l,size=1 cm,color=blue](P,A,E)
\tkzLabelAngle[pos=.8](P,A,E){\tiny$\theta$}

% labels for the points
\tkzLabelPoint[below](B){$B$}   \tkzLabelPoint[below](C){$C$}
\tkzLabelPoint[left](A){$A$}    \tkzLabelPoint[right](D){$D$}
\tkzLabelPoints[above](E,Q)     \tkzLabelPoint[above left](P){$P$}

\end{tikzpicture}

\end{document}


• I need to correct a bug on the macro tkzMarkAngle. I can't put the arrows on the arc (problem with some keys) – Alain Matthes Jul 4 '11 at 13:21
• +1 It is also a nice solution and shorter than what Jake did. – Friendly Ghost Jul 4 '11 at 13:35
• shorter ? yes and no! There are a lot of lines with TikZ behind my code ! Jake's solution is interesting, I can find new ways to write some macros with his code. So thanks for the question ! – Alain Matthes Jul 4 '11 at 13:38

\documentclass[12pt,mathserif]{beamer}
\usepackage[T1]{fontenc}

\usepackage{filecontents}
/side 4 def
/potocar {2 copy cos mul 3 1 roll sin mul} bind def
\end{filecontents*}

\usepackage{pst-eucl}

\usepackage[active,tightpage]{preview}
\PreviewBorder=12pt
\PreviewEnvironment{pspicture}

\begin{document}

\begin{frame}
\begin{pspicture}[showgrid=false](-0.2,-0.2)(8,8)
\pstGeonode[PosAngle={180,225,-45,0,90},CurveType=polygon]
(!0 side){A}
(!0 0){B}
(!80 sin 2 exp side mul 40 sin div 70 sin div 0){C}
(!80 sin side mul 30 sin div 20 potocar){D}
(!50 sin side mul 20 sin div 60 potocar){E}\pause
\pstGeonode[PosAngle={110,80}]
(!80 sin side mul 70 sin div 60 potocar){P}
(!80 sin 2 exp side mul 60 sin div 70 sin div 20 potocar){Q}\pause

\psset{linecolor=red}
\pstLineAB{A}{D}\pause
\pstLineAB{B}{E}\pause
\psset{linecolor=blue}
\pstLineAB{P}{C}\pause
\pstLineAB{B}{D}\pause

\psset
{
linecolor=magenta,
linewidth=0.5\pslinewidth,
arcsep=\pslinewidth,
arrows=<->,
LabelSep=0.75,
}

\tiny
% A
\pstMarkAngle{D}{A}{E}{$\theta$}\pause
\pstMarkAngle{B}{A}{D}{$80^\circ$}\pause
% B
\pstMarkAngle{E}{B}{A}{$30^\circ$}\pause
\pstMarkAngle{D}{B}{E}{$\alpha$}\pause
\pstMarkAngle{C}{B}{D}{$20^\circ$}\pause
% C
\pstMarkAngle{P}{C}{B}{$40^\circ$}\pause
\pstMarkAngle{D}{C}{P}{$70^\circ$}\pause
% D
\pstMarkAngle{B}{D}{C}{$50^\circ$}\pause
\pstMarkAngle{A}{D}{B}{$30^\circ$}\pause
\pstMarkAngle{E}{D}{A}{$50^\circ$}\pause
% E
\pstMarkAngle{B}{E}{D}{$60^\circ$}\pause
\pstMarkAngle[MarkAngleRadius=1.7,LabelSep=1.1]{A}{E}{B}{\rput{(E)}(0,0){$70^\circ-\theta$}}\pause
% P
\pstMarkAngle{D}{P}{E}{$70^\circ$}\pause
\pstMarkAngle{E}{P}{A}{$110^\circ$}\pause
\pstMarkAngle{A}{P}{B}{$70^\circ$}\pause
\pstMarkAngle{B}{P}{C}{$80^\circ$}\pause
\pstMarkAngle{C}{P}{D}{$30^\circ$}\pause
% Q
\end{pspicture}

\end{frame}
\end{document}


GeoGebra is a good option. The resulting diagram can be exported to TikZ, PSTricks or Asymptote code, as well as PDF/EPS/PNG. Saves a great deal of time!