5

In the display, I have three angles that have the same measure. (These are the only three angles that are marked. They are centered at points O, P, and Q.) I am using this code to get familiar with the arc syntax and the let-in syntax. To draw the arc at P, I declare the starting point to be ($(P)!0.5cm!(R)$). This part of the command is correct. I am not sure the reason that the arc is not drawn about P, though.

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections,quotes}



\begin{document}

\vfill
\pagebreak

\noindent \hspace*{\fill}
\begin{tikzpicture}

\coordinate (O) at (0,0);

\draw[-latex,name path=ray_1] (O) -- (10:7);
\coordinate (label_for_ray_r_1) at ($(10:7) +(10:3mm)$);
\node at (label_for_ray_r_1){$r_{1}$};
\node at ($(O)!-3mm!(10:7)$){$O$};
\draw[-latex,name path=ray_2] (O) -- (135:3.5);
\coordinate (label_for_ray_r_2) at ($(135:3.5) +(135:0.3)$);
\node at (label_for_ray_r_2){$r_{2}$};
\draw[-latex,name path=ray_3] (O) -- (342.5:8);
\coordinate (label_for_ray_r_3) at ($(342.5:8) +(342.5:0.3)$);
\node at (label_for_ray_r_3){$r_{3}$};

%The ray opposite to $r_{2}$ is drawn.
\draw[-latex,dashed,name path=opposite_to_ray_2] (O) -- (-45:8);


\coordinate (Q) at (342.5:6.5);
\draw[fill] (Q) circle (1.5pt);
\coordinate (A) at ($(O)!(Q)!(10:7)$);
\node at ($(A)!-3mm!(Q)$){$A$};
\draw[fill,blue] (A) circle (1.5pt);
\draw[name path=path_AQ] (A) -- (Q);


%The projection of Q onto the ray opposite $r_{2}$ is called $P$.
\coordinate (P) at ($(O)!(Q)!(-45:7)$);
\node at ($(P)!3mm!90:(O)$){$P$};
\node at ($(Q)!-3mm!(P)$){$Q$};
\draw[dashed] (Q) -- (P);

%The projection of P onto $r_{1}$ is called $B$.
\coordinate (B) at ($(O)!(P)!(10:7)$);
\node at ($(B)!3mm!-90:(O)$){$B$};
\draw[dashed] (B) -- (P);


%The intersection of the line through P with the same slope as $r_{1}$ and the line through A and Q
%is labeled $R$.
\coordinate (a_point_R_1_in_the_plane_to_determine_R) at ($(P) +(10:3)$);
\path[name path=P_to_R_1] (P) -- (a_point_R_1_in_the_plane_to_determine_R);
\coordinate (a_point_R_2_in_the_plane_to_determine_R) at ($(Q)!-1!(A)$);
\path[name path=P_to_R_2] (Q) -- (a_point_R_2_in_the_plane_to_determine_R);
\coordinate[name intersections={of=P_to_R_1 and P_to_R_2, by={R}}];
\draw[fill] (R) circle (1.5pt);
\draw[dashed] (P) -- (R);
\draw[dashed] (Q) -- (R);

%The label for R is typeset.
\coordinate (label_R_below) at ($(R)!-7mm!(Q)$);
\coordinate (label_R_right) at ($(R)!-7mm!(P)$);
\coordinate (label_R) at ($(label_R_below)!0.5!(label_R_right)$);
\node[blue] at ($(R)!3mm!(label_R)$){$R$};


%An angle is drawn at O.
\draw[draw=blue] (O) ++(10:5mm) arc (10:-45:5mm);


%An angle at P  with measure x is drawn.
\draw[draw=blue] let \p1=($(B)-(P)$), \n1={atan(\y1/\x1)}, \p2=($(Q)-(P)$), \n2={atan(\y2/\x2)} in ($(P)!0.5cm!(B)$) arc (\n1:\n2:0.5);


%An angle at Q  with measure x is drawn.
\draw[draw=blue] let \p1=($(Q)-(P)$), \n1={atan(\y1/\x1)}, \p2=($(Q)-(R)$), \n2={atan(\y2/\x2)} in ($(Q)!0.5cm!(P)$) arc (\n1:\n2:0.5);


\end{tikzpicture}

\end{document}
user74973
  • 4,071
  • All arc are drawn, but as far as I can judge they have wrong starting point. Check your MWE again and please add the picture, which you obtain with your code. – Zarko Aug 06 '15 at 19:33
  • @Zarko How do I add the display that is compiled by TikZ? Why do you think that I have the wrong starting point? – user74973 Aug 07 '15 at 00:21
  • 1
    now you already good answer (I vote for it) ... I try to pointed out, that your code show all three arc (from your question I understand that not), but their starting point is not where you like to have. In this context, the code hasn't any error showing arc and its problem is in geometry. Sketch produced with your code would help to easy understand, what is the problem. Geometry issues can be solved with selection right function ('atan2' instead atan as suggested Tarass in his answer) or manually add or subtract 180 degree from calculated angles (depend on quadrant). – Zarko Aug 07 '15 at 06:28
  • @Zarko And I just voted for your response. Using an old American idiom: one hand washes another. – user74973 Aug 07 '15 at 20:21
  • @Zarko May you humor me by correcting the code for the angle at either P or R? I want to use just atan. – user74973 Aug 07 '15 at 20:21
  • meanwhile I deleted my tests ... :_(. I can provide an answer, but answer of Taras is much better and easier to use -- you do not need to thing about pale quadrants. I will see, what I can do now. – Zarko Aug 07 '15 at 20:44

3 Answers3

5

The problem comes from the fact that atan give answer modulo 180° because it doesn't take acount of quadrant, use atan2 instead. You may think use macro instead on repetiting code. Once it works, make a macro.

On can compare atan in red, atan2 in blue : the second computes itself the right non oriented angle but both are not sentive to trignometric orientation.

In green : solves the two problems.

enter image description here

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections,quotes}


\newcommand{\AngleBad}[4][red]{%
\draw[#1] let
    \p1=($(#2)-(#3)$),
    \n1={atan(\y1/\x1)},
    \p2=($(#4)-(#3)$),
    \n2={atan(\y2/\x2)} in
    ($(#3)!.4cm!(#2)$) arc (\n1:\n2:.4) ;
}

\newcommand{\AngleBetter}[4][blue]{%
\draw[#1] let
    \p1=($(#2)-(#3)$),
    \n1={atan2(\y1,\x1)},
    \p2=($(#4)-(#3)$),
    \n2={atan2(\y2,\x2)} in
    ($(#3)!.5cm!(#2)$) arc (\n1:\n2:.5) ;
}

\newcommand{\MarkAngle}[4][green]{%
    \pgfmathanglebetweenpoints{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#2}{center}}%
    \let\AngleA\pgfmathresult
    \pgfmathanglebetweenpoints{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#4}{center}}%
    \let\AngleB\pgfmathresult
    \pgfmathparse{ifthenelse(\AngleA>\AngleB,\AngleA-360,\AngleA)}
    \let\AngleA\pgfmathresult ; 
    \draw[#1] ($(#3)!.6cm!(#2)$) arc (\AngleA:\AngleB:.6) ; }


\begin{document}

\vfill
\pagebreak

\noindent \hspace*{\fill}
\begin{tikzpicture}

\coordinate (O) at (0,0);

\draw[-latex,name path=ray_1] (O) -- (10:7);
\coordinate (label_for_ray_r_1) at ($(10:7) +(10:3mm)$);
\node at (label_for_ray_r_1){$r_{1}$};
\node at ($(O)!-3mm!(10:7)$){$O$};
\draw[-latex,name path=ray_2] (O) -- (135:3.5);
\coordinate (label_for_ray_r_2) at ($(135:3.5) +(135:0.3)$);
\node at (label_for_ray_r_2){$r_{2}$};
\draw[-latex,name path=ray_3] (O) -- (342.5:8);
\coordinate (label_for_ray_r_3) at ($(342.5:8) +(342.5:0.3)$);
\node at (label_for_ray_r_3){$r_{3}$};

%The ray opposite to $r_{2}$ is drawn.
\draw[-latex,dashed,name path=opposite_to_ray_2] (O) -- (-45:8);


\coordinate (Q) at (342.5:6.5);
\draw[fill] (Q) circle (1.5pt);
\coordinate (A) at ($(O)!(Q)!(10:7)$);
\node at ($(A)!-3mm!(Q)$){$A$};
\draw[fill,blue] (A) circle (1.5pt);
\draw[name path=path_AQ] (A) -- (Q);


%The projection of Q onto the ray opposite $r_{2}$ is called $P$.
\coordinate (P) at ($(O)!(Q)!(-45:7)$);
\node at ($(P)!3mm!90:(O)$){$P$};
\node at ($(Q)!-3mm!(P)$){$Q$};
\draw[dashed] (Q) -- (P);

%The projection of P onto $r_{1}$ is called $B$.
\coordinate (B) at ($(O)!(P)!(10:7)$);
\node at ($(B)!3mm!-90:(O)$){$B$};
\draw[dashed] (B) -- (P);


%The intersection of the line through P with the same slope as $r_{1}$ and the line through A and Q
%is labeled $R$.
\coordinate (a_point_R_1_in_the_plane_to_determine_R) at ($(P) +(10:3)$);
\path[name path=P_to_R_1] (P) -- (a_point_R_1_in_the_plane_to_determine_R);
\coordinate (a_point_R_2_in_the_plane_to_determine_R) at ($(Q)!-1!(A)$);
\path[name path=P_to_R_2] (Q) -- (a_point_R_2_in_the_plane_to_determine_R);
\coordinate[name intersections={of=P_to_R_1 and P_to_R_2, by={R}}];
\draw[fill] (R) circle (1.5pt);
\draw[dashed] (P) -- (R);
\draw[dashed] (Q) -- (R);

%The label for R is typeset.
\coordinate (label_R_below) at ($(R)!-7mm!(Q)$);
\coordinate (label_R_right) at ($(R)!-7mm!(P)$);
\coordinate (label_R) at ($(label_R_below)!0.5!(label_R_right)$);
\node[blue] at ($(R)!3mm!(label_R)$){$R$};


\AngleBad{P}{O}{B}
\AngleBad{B}{O}{P} % not sensitive to trigonometric orientation
\AngleBad{P}{Q}{R}
\AngleBad{Q}{P}{B}

\AngleBetter{P}{O}{B}
\AngleBetter{B}{O}{P} % not sensitive to trigonometric orientation
\AngleBetter{P}{Q}{R}
\AngleBetter{Q}{P}{B}

\MarkAngle{P}{O}{B} % sensitive to trigonometric orientation
\MarkAngle[dashed,green]{B}{O}{P}
\MarkAngle{P}{Q}{R}
\MarkAngle{Q}{P}{B}


\end{tikzpicture}

\end{document}
Tarass
  • 16,912
  • Your code gives me what I want. I really don't want to use a \newcommand for this. (I am not familiar with the syntax, too.) I interpret your comment to mean atan only gives computations between -90 and 90. There must be a way to code +90 or -90. – user74973 Aug 07 '15 at 00:54
  • @user74973 You don't have to use \newcommand. That's just for convenience. You can use atan2 without doing that. – cfr Aug 07 '15 at 01:34
  • @cfr What is the difference between atan2 and atan? I understand that in my command \draw[draw=blue] let \p1=($(B)-(P)$), \n1={atan(\y1/\x1)}, \p2=($(Q)-(P)$), \n2={atan(\y2/\x2)} in ($(P)!0.5cm!(B)$) arc (\n1:\n2:0.5); terminal side of the angle is in Quadrant II and that the arctan function is defined on the interval (-\pi/2, \pi/2). I do not know how TikZ compiles the code from Tarass to give a circular arc at P indicating $\angle{BPQ}$. – user74973 Aug 08 '15 at 15:06
  • The main difference between atan and atan2 is that atan2 take two argument instread of one, then atan2 can compute in witch quadran is the node and then avoid to give a wrong answer (modulo 180), it explains tikz can find the right angle. – Tarass Aug 08 '15 at 16:33
  • 1
    I made an extention to my previous answer then will see the difference between atan, atan2 and the lacks of this methods, a third one that solve the problem. The macro approach is optional, it just avoids tapping endless the same code with random mystakes. – Tarass Aug 08 '15 at 16:50
  • 2
    @user74973 atan goes from a number (e.g. 1) to an angle (e.g. 45). As such, it knows nothing about which quadrant you're in. atan2 goes from a coordinate (e.g. (1,1)) to an angle, taking account of which quadrant the coordinate is in. – cfr Aug 08 '15 at 18:14
5

I admire elegance of Tarass answer, but OP challenge me to show solution without use of atan. In this solution you need to know the quadrant where is angle and accordingly add or subtracts 180 degrees. O.K, here we go:

\documentclass[border=1mm,
               class=amsart,
               preview]{standalone}
\usepackage{amsmath,amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections,quotes}

    \begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);

\draw[-latex,name path=ray_1] (O) -- (10:7);
\coordinate (label_for_ray_r_1) at ($(10:7) +(10:3mm)$);
\node at (label_for_ray_r_1){$r_{1}$};
\node at ($(O)!-3mm!(10:7)$){$O$};
\draw[-latex,name path=ray_2] (O) -- (135:3.5);
\coordinate (label_for_ray_r_2) at ($(135:3.5) +(135:0.3)$);
\node at (label_for_ray_r_2){$r_{2}$};
\draw[-latex,name path=ray_3] (O) -- (342.5:8);
\coordinate (label_for_ray_r_3) at ($(342.5:8) +(342.5:0.3)$);
\node at (label_for_ray_r_3){$r_{3}$};

%The ray opposite to $r_{2}$ is drawn.
\draw[-latex,dashed,name path=opposite_to_ray_2] (O) -- (-45:8);

\coordinate (Q) at (342.5:6.5);
\draw[fill] (Q) circle (1.5pt);
\coordinate (A) at ($(O)!(Q)!(10:7)$);
\node at ($(A)!-3mm!(Q)$){$A$};
\draw[fill,blue] (A) circle (1.5pt);
\draw[name path=path_AQ] (A) -- (Q);

%The projection of Q onto the ray opposite $r_{2}$ is called $P$.
\coordinate (P) at ($(O)!(Q)!(-45:7)$);
\node at ($(P)!3mm!90:(O)$){$P$};
\node at ($(Q)!-3mm!(P)$){$Q$};
\draw[dashed] (Q) -- (P);

%The projection of P onto $r_{1}$ is called $B$.
\coordinate (B) at ($(O)!(P)!(10:7)$);
\node at ($(B)!3mm!-90:(O)$){$B$};
\draw[dashed] (B) -- (P);

%The intersection of the line through P with the same slope as $r_{1}$ and the line through A and Q is labeled $R$.
\coordinate (a_point_R_1_in_the_plane_to_determine_R) at ($(P) +(10:3)$);
\path[name path=P_to_R_1] (P) -- (a_point_R_1_in_the_plane_to_determine_R);
\coordinate (a_point_R_2_in_the_plane_to_determine_R) at ($(Q)!-1!(A)$);
\path[name path=P_to_R_2] (Q) -- (a_point_R_2_in_the_plane_to_determine_R);
\coordinate[name intersections={of=P_to_R_1 and P_to_R_2, by={R}}];
\draw[fill] (R) circle (1.5pt);
\draw[dashed] (P) -- (R);
\draw[dashed] (Q) -- (R);

%The label for R is typeset.
\coordinate (label_R_below) at ($(R)!-7mm!(Q)$);
\coordinate (label_R_right) at ($(R)!-7mm!(P)$);
\coordinate (label_R) at ($(label_R_below)!0.5!(label_R_right)$);
\node[blue] at ($(R)!3mm!(label_R)$){$R$};

%Angles at O, P and Q:
\path[draw=blue] 
%An angle is drawn at O.
    (O) ++(10:5mm) arc (10:-45:5mm)
%An angle at P  with measure x is drawn.
    let \p1=($(B)-(P)$), 
        \n1={atan(\y1/\x1)}, 
        \p2=($(Q)-(P)$), 
        \n2={atan(\y2/\x2)} in 
    ($(P)!0.5cm!(B)$) arc (\n1+180:\n2:0.5)% added 180 degree to \n1
%An angle at Q  with measure x is drawn.
    let \p1=($(Q)-(P)$), 
        \n1={atan(\y1/\x1)}, 
        \p2=($(Q)-(R)$),
        \n2={atan(\y2/\x2)} in
    ($(Q)!0.5cm!(P)$) arc (\n1-180:\n2:0.5);% substracted 180 degree from \n1
\end{tikzpicture}
    \end{document}

And obtained picture: enter image description here

Zarko
  • 296,517
  • Without atan could be : \newcommand{\MarkAngle}[4][blue]{% \pgfmathanglebetweenpoints% {\pgfpointanchor{#3}{center}}% {\pgfpointanchor{#2}{center}}% \let\AngleA\pgfmathresult \pgfmathanglebetweenpoints% {\pgfpointanchor{#3}{center}}% {\pgfpointanchor{#4}{center}}% \let\AngleB\pgfmathresult \draw[#1] ($(#3)!.5cm!(#2)$) arc (\AngleA:\AngleB:.5) ; } – Tarass Aug 08 '15 at 06:20
  • @Tarass, even with more elementary math and geometry! Very nice! – Zarko Aug 08 '15 at 06:28
  • And this code makes the difference between POB and BOP angle, my previous doesn't, OP's needs double manual correction. – Tarass Aug 08 '15 at 06:47
  • Yes, it is. I warning OP about deficiency of my approach ... however, it can serve as exercise for elementary geometry :-). And as I said, personally I will use your answer. – Zarko Aug 08 '15 at 07:10
  • @Zarko Yes, you can say that my insistence to use just atan is some nice practice in geometry. I primarily want to get familiar with using arc. – user74973 Aug 08 '15 at 15:15
  • @Zarko I have a question about your code to draw an arc at Q. You have the command ($(Q)!0.5cm!(P)$) arc (\n1-180:\n2:0.5);. Why does TikZ draw the "wrong angle" if \n1-180 is replaced with \n1+180? (I think your answer will illustrate the syntax of the arc command.) – user74973 Aug 08 '15 at 16:28
  • 1
    You need to sketch triangle of interest and look which angle you calculate and which you actually need. In case of subtractions of 180 you need supplementary angle (I'm not mathematician nor English native speaker, so sorry for rude explanation), in case of summation you need angle start on line through of angle top on it opposite side. – Zarko Aug 08 '15 at 17:32
3

Here's a version in Metapost for comparison. In particular I think the drawing is simplified by the use of rotated and angle which were deliberately designed to remove the need for you to think explicitly about sines, cosines, and arc-tangents. (See the Metafont Book, p.67).

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

% define the end points of the three rays
z1 = right scaled 200 rotated 10;
z2 = right scaled 100 rotated 135;
z3 = right scaled 225 rotated -17.5;

% define the other points, relative to Q
pair A, B, P, Q, R;
Q = 0.8125 z3;
A = whatever[origin, z1]; A-Q = whatever * z1 rotated 90;
P = whatever[origin, z2]; P-Q = whatever * z2 rotated 90;
B = whatever[origin, z1]; B-P = whatever * z1 rotated 90;
R = whatever[A,Q];        R-P = whatever * (B-P) rotated 90;

% mark the angles 
drawoptions(withcolor .67 blue);
draw fullcircle scaled 30 rotated angle (Q-P) shifted P cutafter (P--B);
draw fullcircle scaled 30 rotated angle (P-Q) shifted Q cutafter (Q--R);
draw fullcircle scaled 30 rotated angle P               cutafter (origin--z1);
drawoptions();

% draw the rays and A--Q
drawarrow origin -- z1; label(btex $r_1$ etex, z1 scaled 1.05);
drawarrow origin -- z2; label(btex $r_2$ etex, z2 scaled 1.08);
drawarrow origin -- z3; label(btex $r_3$ etex, z3 scaled 1.05);
draw A--Q;

% draw the dashed lines
drawoptions(dashed evenly);
draw B--P--R--Q--P;
drawarrow origin -- P scaled 4/3;
drawoptions();

% label the points
dotlabel.urt(btex $Q$ etex, Q);
dotlabel.top(btex $A$ etex, A);
dotlabel.lrt(btex $R$ etex, R) withcolor .67 blue;

label.top (btex $B$ etex, B);
label.llft(btex $P$ etex, P);
label.llft(btex $O$ etex, origin);

endfig;
end.

Note: the construction P = whatever[a,b] defines P as a point that lies somewhere on the line through a and b. While P-Q = whatever * (a-b) says that "the direction of P from Q should be some multiple of the direction of a from b". You can, of course, omit b when it is the origin.

Plain MP defines origin=(0,0) for you.

Thruston
  • 42,268