TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

\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$}





enter image description here

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

share|improve this question
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
up vote 10 down vote accepted

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


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



enter image description here

share|improve this answer
I had to think about it, but I suppose it should be possible. – Herbert 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 – Herbert 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 – Herbert Jul 4 '11 at 12:45
+1 for the edit. Thanks. – Friendly Ghost Jul 4 '11 at 13:06

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.

tikz example


% Command for adding angle labels
    \pgfmathtruncatemacro\startangle{round( 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

% Wrapper if angle unknown

% Define length of first line
% Define length of "rays" used for finding intersections


% 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
\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}

share|improve this answer
+1 for your effort. It is a nice solution too. Thanks. – Friendly Ghost Jul 4 '11 at 11:58
@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


        \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

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

        \tkzMarkAngle[arc=ll,size=1 cm,color=red](P,B,A) 
        \tkzMarkAngle[arc=ll,size=1 cm,color=red](Q,P,D) 
        \tkzMarkAngle[arc=ll,size=1 cm,color=red](P,D,Q) 
        \tkzMarkAngle[arc=l,size=1 cm](C,B,D) 
        \tkzMarkAngle[arc=l,size=1 cm](Q,C,B) 
        \tkzMarkAngle[arc=l,size=1 cm](B,D,C) 
        \tkzMarkAngle[arc=l,size=1 cm](D,C,P) 
        \tkzMarkAngle[arc=l,size=1 cm](E,D,P) 
        \tkzMarkAngle[arc=l,size=1 cm,color=blue](D,B,P) 
        \tkzMarkAngle[arc=l,size=1 cm,color=blue](P,A,E) 

        % 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$} 



enter image description here

share|improve this answer
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

enter image description here


    /side 4 def
    /potocar {2 copy cos mul 3 1 roll sin mul} bind def




    (!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
    (!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



% A
% B
% C
% D
% E
% P
% Q

share|improve this answer

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!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.