3

TikZ compiles the following code to display two lines that intersect at right angles. A small square, drawn in black, with edge length 3mm and with a vertex at the point of intersection, indicates that the lines intersect at right angles. The right-angle mark bends around the dot at the origin, though. How can I keep I can avoid this distortion? (I want the right-angle mark to obscure the y-axis but not the dot at the origin.)

This is similar code that I had posted when I was asking about the clipping of arrowheads. I think one way to keep of doing this is to issue commands \path[name path=up] (-3.75,3.75) -- (3.75,3.75);, ... \path[name path=left] (-3.75,-3.75) -- (-3.75,3.75);, and to use the intersections package to label the coordinates of the four intersections between the given lines and these four paths. I am not familiar with using the intersections package, though.

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,quotes}


\begin{document}


\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt}]

\draw[draw=gray!30,latex-latex] (-3.75,0) +(-0.25cm,0) -- (3.75,0) -- +(0.25cm,0) node[below right] {$x$};
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);

\clip (-3.75,-3.75) rectangle (3.75,3.75);

\draw[gray,dashed,line width=0.1pt] (-3.75,3.75) -- (3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (3.75,-3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (-3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (3.75,-3.75) -- (3.75,3.75);

\draw[draw=blue!30,-latex] (0,0) -- (142:5);
\draw[draw=blue!30,-latex] (0,0) -- (-38:5);
\draw[draw=green!50,-latex] (0,0) -- (52:5);
\draw[draw=green!50,-latex] (0,0) -- (-128:5);

\coordinate[p,label={[fill=white]below right:$O$}] (O) at (0,0);

\coordinate (A) at (0:1);
\coordinate (B) at (52:1);
\path pic[draw, angle radius=5mm,"$\phi$",angle eccentricity=1.25] {angle = A--O--B};

\coordinate (a) at (180:1);
\coordinate (b) at (142:1);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = b--O--a};

\coordinate (P) at (142:1);
\coordinate (Q) at (52:1);

\coordinate (R) at ($(O)!4mm! -45:(P)$);
\draw (R) -- ($(O)!(R)!(P)$);
\draw (R) -- ($(O)!(R)!(Q)$);


\filldraw[fill=white] (O) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;


\end{tikzpicture}

\end{document}
  • Change your last line before \end{tikzpicture} to this: \draw (O.center)--($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$)-- cycle; – AboAmmar Apr 29 '15 at 15:09
3

You are using the style p to the coordinate O where p is

p/.style={circle, fill,inner sep=1.5pt}

i.e., that coordinate has an inner sep. Hence when you start drawing the right angle mark from O, it starts from the border of O and with cycle it comes back to the same border point. Hence you get the distortion. To avoid this use O.center.

Oh no!, it appears on that black circle at O. To avoid this, use the tikz library backgrounds and shove the entire right angle mark on the back ground layer like

\begin{scope}[on background layer]
\filldraw[fill=white] (O.center) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{scope}

But you want the right angle mark to obscure the y axis which isn't happening. Therefore move the line that draws the y axis in to the previous scope before the right angle code line like

\begin{scope}[on background layer]
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);
\filldraw[fill=white] (O.center) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{scope}

Full code:

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,quotes,backgrounds}


\begin{document}


\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt}]

\draw[draw=gray!30,latex-latex] (-3.75,0) +(-0.25cm,0) -- (3.75,0) -- +(0.25cm,0) node[below right] {$x$};

\clip (-3.75,-3.75) rectangle (3.75,3.75);

\draw[gray,dashed,line width=0.1pt] (-3.75,3.75) -- (3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (3.75,-3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (-3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (3.75,-3.75) -- (3.75,3.75);

\draw[draw=blue!30,-latex] (0,0) -- (142:5);
\draw[draw=blue!30,-latex] (0,0) -- (-38:5);
\draw[draw=green!50,-latex] (0,0) -- (52:5);
\draw[draw=green!50,-latex] (0,0) -- (-128:5);

\coordinate[p,label={[fill=white]below right:$O$}] (O) at (0,0);

\coordinate (A) at (0:1);
\coordinate (B) at (52:1);
\path pic[draw, angle radius=5mm,"$\phi$",angle eccentricity=1.25] {angle = A--O--B};

\coordinate (a) at (180:1);
\coordinate (b) at (142:1);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = b--O--a};

\coordinate (P) at (142:1);
\coordinate (Q) at (52:1);

\coordinate (R) at ($(O)!4mm! -45:(P)$);
\draw (R) -- ($(O)!(R)!(P)$);
\draw (R) -- ($(O)!(R)!(Q)$);

\begin{scope}[on background layer]
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);
\filldraw[fill=white] (O.center) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{scope}

\end{tikzpicture}

\end{document}

enter image description here

  • I will look in the manual for the option "on background layer" for descriptions. I see that it is described in Chapter 43 in the manual. Can you have the code that you have in the scope environment at the beginning of the code? – user74973 Apr 29 '15 at 22:03
  • @user74973 You can but the coordinates P, Q, R, and O are un known at the beginning. You can put the yaxis separately inside one scope with background layer in the beginning and the right angle inside another later. – user11232 Apr 29 '15 at 23:15
1

Why a square to signal a right angle? You can do it with two lines. Just replace

\filldraw[fill=white] (O) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;

with

\filldraw[fill=white] ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$);

angle figure

However, if you really want the square, the problem is that you didn't define the coordinate O, so below the other coordinates add \coordinate (O) at (0,0);. I coloured it red to show it.

figure angle

In order not to cover also the origin point add this in the preamble

\pgfdeclarelayer{bg}   
\pgfsetlayers{bg,main}

And do this:

\begin{pgfonlayer}{bg}
\filldraw[red,fill=white] (O) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{pgfonlayer}
  • I agree that having a black square to give the right-angle mark is unseemly. I just wanted to know why it was being distorted. Harish Kumar gave me an explanation. – user74973 Apr 29 '15 at 21:22
  • In what chapter of the manual is the code \pgfdeclarelayer{bg} explained? – user74973 Apr 29 '15 at 21:25
  • @user74973 I had learned it here actually, but it's "90.2 Declaring Layers", then 90.3 and so on, on page 837 of the manual. – Alenanno Apr 29 '15 at 21:46
  • I edited the code to put arrowheads on the lines. (See the last six commands.) TikZ does not compile it. Can you fix it? – user74973 Apr 29 '15 at 22:32
  • @user74973 Would you mind asking that in a separate question and rollback your revision to the previous original question? I think it'd be better because the new edit is unrelated enough to grant a follow-up question. You can link this question in the new one as reference. – Alenanno Apr 29 '15 at 23:30

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.