This provides good details on How to draw a line passing through a point and perpendicular to another?. What I would like to do is to extend this somehow to add the usual geometry symbol to indicate that the two lines are indeed perpendicular. I could code a manual solution for each situation, but would like a macro, one that would draw it of an appropriate size, and allow me to choose the orientation (i.e., select one of the four quadrants) for this symbol.


2 Answers 2


Here's one possible approach that uses a TikZ style. You insert the angle symbol by using the style

right angle symbol={<Point 1>}{<Point 2>}{<Point 3>}

in a draw command, where <Point 1> and <Point 2> are two points on a line (A and B in the image below), and <Point 3> is a point on the perpendicular line (Q or P in the image below). If you want the angle symbol on its own, just use it in a new draw command:

\draw [right angle symbol={<Point 1>}{<Point 2>}{<Point 3>}];

The quadrant can be selected by using right angle quadrant=<1-4>, the size by using right angle length=<length>. Both these options have to be called before right angle symbol.

right angles with symbols in TikZ


    right angle quadrant/.code={
        \pgfmathsetmacro\quadranta{{1,1,-1,-1}[#1-1]}     % Arrays for selecting quadrant
    right angle quadrant=1, % Make sure it is set, even if not called explicitly
    right angle length/.code={\def\rightanglelength{#1}},   % Length of symbol
    right angle length=2ex, % Make sure it is set...
    right angle symbol/.style n args={3}{
        insert path={
            let \p0 = ($(#1)!(#3)!(#2)$) in     % Intersection
                let \p1 = ($(\p0)!\quadranta*\rightanglelength!(#3)$), % Point on base line
                \p2 = ($(\p0)!\quadrantb*\rightanglelength!(#2)$) in % Point on perpendicular line
                let \p3 = ($(\p1)+(\p2)-(\p0)$) in  % Corner point of symbol
            (\p1) -- (\p3) -- (\p2)

\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
  extended line/.style={shorten >=-#1,shorten <=-#1},
  extended line/.default=1cm]

\node [dot=A] at (0,0) {};
\node [dot=B] at (3,1) {};
\node [dot=P] at (0.9,-1.2) {};
\node [dot=Q] at (1.3,2.2) {};

\draw [extended line=0.5cm] (A) -- (B);
\draw [extended line] ($(A)!(P)!(B)$) -- (P);

\draw [red,right angle symbol={A}{B}{P}];

\draw [extended line,right angle quadrant=3,right angle symbol={A}{B}{Q}] ($(A)!(Q)!(B)$) -- (Q);
  • @Altermundus makes a good point about right angle symbol={A}{P}{B}. A better method syntax might be right angle symbol={A}{B}{P} to specify which angle to place the symbol on. Jun 29, 2011 at 22:03
  • @Peter: The original order reflected the syntax of the calc syntax that is used to calculate the projection of P on AB. I've changed it to {A}{B}{P} now.
    – Jake
    Jun 29, 2011 at 23:02
  • I get an error latexing this exact file: ! Argument of \pgfmath@afterquick has an extra }. <inserted text> \par l.21 } The braces seem balanced though.
    – Liam
    Jan 14, 2013 at 16:00
  • @Liam: It compiles fine for me. Are you sure you copied the code correctly? Also, are you using the current version of PGF (v. 2.1)?
    – Jake
    Jan 14, 2013 at 16:04
  • @Jake Package: pgf 2008/01/15 v2.00 (rcs-revision 1.12) from \pgfversion in Debian stable.
    – Liam
    Jan 14, 2013 at 16:22

Another possibility is to use my package tkz-euclide (now on ctan and texlive 2011) but you don't need to get all the objects that I defined. Only angles are necessary. I take the Jake's example to show you that you can mix tikz and tkz. \usetkzobj{angles} this macro loads all the macros for the angles, if you need other objects \usetkzobj{angles,polygons} the syntax is the same as \usetikzlibrary and if you want all the objects , you write \usetkzobj{all}

\usepackage{tkz-euclide} % loads  TikZ and tkz-base
\usetkzobj{angles} % important you want to use angles

\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
  extended line/.style={shorten >=-#1,shorten <=-#1},
  extended line/.default=1cm]
\node [dot=A] at (0,0) {};
\node [dot=B] at (3,1) {};
\node [dot=P] at (0.9,-1.2) {};

%\draw [extended line=0.5cm] (A) -- (B);
% In tkz-euclide I defined something like extend line 
% but I prefer my method because I add a percentage of the segment  at each sides
% with [add = % and %] left and right 
\tkzDrawLine[add=1 and .5](A,B) % with 1 you double the line BA from A
\draw [extended line] ($(A)!(P)!(B)$) coordinate (H) -- (P);
 % I named the projection H
  \tkzMarkRightAngle[fill=blue!20,size=.5](A,H,P) % size number in cm
  % and you need to give the points in an order counterclockwise

% Now an example with only tkz-euclide
  \tkzDrawLine[add= 0.5 and 0.8,color=blue](A,B)
   \tkzDefPointBy[projection=onto B--A](C)  \tkzGetPoint{H}
  \tkzDrawLine[add = .5 and .2,color=red](C,H)
  \tkzDrawPoints(A,B,C)\tkzLabelPoints(A,B,C) % better now


enter image description here

  • @Altermundus: tkz-euclide seems very useful, but Jake's answer does not require another package so going to accept that for now. Hope to start experimenting with tkz-euclide soon. Jun 29, 2011 at 21:11
  • @Peter No problem. We find solutions and you make your choice , it's normal. My only problem with Jake'solution it's the use of a quadrant and the syntaxe right angle symbol={A}{P}{B}. Jun 29, 2011 at 21:24
  • @Altermundus: The ability to specify a quadrant was an explicit requirement by the OP. It is an optional argument in my solution, so I don't see the drawback. Also, could you be more specific regarding what you don't like about the syntax? Would you prefer if the points were comma separated, if their order was changed, or if the name was shorter? Either of that is easily possible.
    – Jake
    Jun 29, 2011 at 22:00
  • @Jake Sorry for my english. These are only minor complaints about the syntax. right angle symbol={A}{P}{B} is not necessary if you use quadrant. Perhaps, it's preferable to name (H) the projection of P on the line AB. This can be useful for the OP. You can write now right angle=H. Now you can use a quadrant or write (A,H,P) or (P,H,B). Jun 30, 2011 at 5:07
  • @Jake You have a problem if A,B and P are aligned ! Jun 30, 2011 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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