5

I have quadrilateral ABCD inscribed in a circle. I am to locate a point P on the line through C and D so that D is between it and C and

|DP| = (|AD|*|BC|)/|AB|.

The length of DP is drawn too long. What is wrong with the code that I have for locating P?

\documentclass{amsart}


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

\begin{document}


\begin{tikzpicture}

\coordinate (O) at (0,0);
\draw[dashed] (195:2.5) arc (195:160:2.5);
\draw (160:2.5) arc (160:5:2.5);
\draw[dashed] (-15:2.5) arc (-15:5:2.5);


%Chord $\overline{AB}$ is drawn.
\path (100:2.5) coordinate (A) (160:2.5) coordinate (B) (5:2.5) coordinate (C) (40:2.5) coordinate (D);
\draw (A) -- (B) -- (C) -- (D) -- cycle;
\draw (A) -- (C);
\draw (B) -- (D);


%Labels for the endpoints of the chord AB are typeset.
\draw let \p1=($(A)-(B)$), \n1={atan(\y1/\x1)}, \p2=($(A)-(D)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+(\n2+180))+180}, inner sep=0] at ($(A) +({0.5*(\n1+(\n2+180))}:0.15)$){\textit{A}};
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor=\n1, inner sep=0] at ($(B) +({\n1+180}:0.15)$){\textit{B}};
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+180}, inner sep=0] at ($(C) +(\n1:0.15)$){\textit{C}};
\draw let \p1=($(A)-(D)$), \n1={atan(\y1/\x1)}, \p2=($(C)-(D)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+(\n2+180))+180}, inner sep=0] at ($(D) +({0.5*(\n1+(\n2+180))}:0.15)$){\textit{D}};


%P is a point on the line through C and D so that D is between it and C, and |PD| = (|AD|*|BC|)/|AB|.
\path let \p1=($(A)-(B)$), \n1={veclen(\x1,\y1)}, \p2=($(A)-(D)$), \n2={veclen(\x2,\y2)}, \p3=($(B)-(C)$), \n3={veclen(\x3,\y3)} in coordinate (P) at
($(D)!{(-1*\n2*\n3/\n1)*1cm}!(C)$);
\draw[fill] (P) circle (1.5pt);
\draw[dashed] (P) -- (D);


\end{tikzpicture}

\end{document}
user74973
  • 4,071
  • In the location of (D) you multiply with 1cm which is blowing up. The computations are in pt so you need 1pt. – percusse Mar 10 '18 at 21:13
  • It is for the location of P. – user74973 Mar 10 '18 at 21:21
  • Are you saying that I should replace cm with pt? – user74973 Mar 10 '18 at 21:21
  • 1
    Yes, or just remove it altogether, i.e. ($(D)!{-1*\n2*\n3/\n1}!(C)$). Edit: All the \nX are lengths in pt. – Torbjørn T. Mar 10 '18 at 22:49
  • @Torbjørn T. Is the 2.5 in the command \draw (160:2.5) arc (160:5:2.5) a measurement in points? – user74973 Mar 11 '18 at 17:21
  • @Torbjørn T. What is the command if I wanted P located on the line through C and D that is at a distance from D equal to (\n2*\n3)/\n1 times the distance between C and D? – user74973 Mar 11 '18 at 17:22
  • 1
    For the first, surely if you look at your output you'll see that it obviously isn't in pt (1pt is about 0.3mm). In that case it'll be cm. For the second, you need to convert from pt to cm, so divide by 28.45 (https://tex.stackexchange.com/q/8260). – Torbjørn T. Mar 11 '18 at 17:40

2 Answers2

8

You ask two quite different questions, actually. To position P so that |DP| = (|AD|*|BC|)/|AB|, you only need to remove *1cm from your code, i.e.

coordinate (P) at ($(D)!{(-1*\n2*\n3/\n1)}!(C)$)

and not

coordinate (P) at ($(D)!{(-1*\n2*\n3/\n1)*1cm}!(C)$)

The reason is that \n2*\n3/\n1 is already a length, in pt, and as percusse says, for the calculation pgf will convert 1cm to pt as well. So you get a length that is 28.45 times too long, as 1cm is about 28.45pt.

To see this you can print out the values in a node like this

\path let 
 \p1=($(A)-(B)$),
 \n1={veclen(\x1,\y1)},
 \p2=($(A)-(D)$),
 \n2={veclen(\x2,\y2)},
 \p3=($(B)-(C)$),
 \n3={veclen(\x3,\y3)},
 \n4={-1*\n2*\n3/\n1},
 \n5={1cm},
 \n6={\n4*1cm}
in
 coordinate (P) at ($(D)!\n4!(C)$)
 node [right=5mm] at (C|-A) {%
   $\begin{aligned}
    n_1 &= \n1 \\
    n_2 &= \n2 \\
    n_3 &= \n3 \\
    n_4 &= \n4 \\
    1\,\mathrm{cm} &= \n5 \\
    n_4 \cdot 1\,\mathrm{cm} &= \n6
   \end{aligned}$};

(note the aligned environment requires \usepackage{amsmath})

which gives you this:

enter image description here

Old answer

In your comment you asked a different question:

What is the command if I wanted P located on the line through C and D that is at a distance from D equal to (\n2*\n3)/\n1 times the distance between C and D?

There are a couple of things to consider. First of all, veclen will give you a length in pt, because \xN/\yN will be in pt. So because the rest of the diagram uses cm, you need to scale the result. I tend to just remember that 1in = 72.27pt = 2.54cm, so multiply by 2.54/72.27, but that corresponds to dividing by about 28.45. (See also What are the various units (ex, em, in, pt, bp, dd, pc) expressed in mm?.)

Second, \nN will regardless return a length in pt unless told otherwise, so you need to use the scalar function to strip the unit. This is needed because with the ($(a)!X!(b)!$) syntax, X can be either a length or a factor. You want a factor.

output of code

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}
\begin{tikzpicture}

\coordinate (O) at (0,0);
\draw[dashed] (195:2.5) arc (195:160:2.5);
\draw (160:2.5) arc (160:5:2.5);
\draw[dashed] (-15:2.5) arc (-15:5:2.5);


%Chord $\overline{AB}$ is drawn.
\path (100:2.5) coordinate (A) (160:2.5) coordinate (B) (5:2.5) coordinate (C) (40:2.5) coordinate (D);
\draw (A) -- (B) -- (C) -- (D) -- cycle;
\draw (A) -- (C);
\draw (B) -- (D);


%Labels for the endpoints of the chord AB are typeset.
\draw let \p1=($(A)-(B)$), \n1={atan(\y1/\x1)}, \p2=($(A)-(D)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+(\n2+180))+180}, inner sep=0] at ($(A) +({0.5*(\n1+(\n2+180))}:0.15)$){\textit{A}};
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor=\n1, inner sep=0] at ($(B) +({\n1+180}:0.15)$){\textit{B}};
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+180}, inner sep=0] at ($(C) +(\n1:0.15)$){\textit{C}};
\draw let \p1=($(A)-(D)$), \n1={atan(\y1/\x1)}, \p2=($(C)-(D)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+(\n2+180))+180}, inner sep=0] at ($(D) +({0.5*(\n1+(\n2+180))}:0.15)$){\textit{D}};


%P is a point on the line through C and D so that D is between it and C, and |PD| = (|AD|*|BC|)/|AB|.
\path let
  \p1=($(A)-(B)$),
  \n1={veclen(\x1,\y1)*2.54/72.27}, % pt -> cm; 1in = 72.27pt = 2.54cm
  \p2=($(A)-(D)$),
  \n2={veclen(\x2,\y2)*2.54/72.27},
  \p3=($(B)-(C)$),
  \n3={veclen(\x3,\y3)*2.54/72.27},
  \n4={-scalar(\n2*\n3/\n1)} % scalar strips the unit, so you get 4.88, not 4.88pt
in
coordinate (P) at  ($(D)!\n4!(C)$);

\draw[fill] (P) circle (1.5pt);
\draw[dashed] (P) -- (D);

\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
  • I appreciate the code. – user74973 Mar 12 '18 at 03:48
  • You say that the calc package give \n1, \n2, and \n3 in units of points, and a computation like (\n2*\n3)/\n1 is in units of points ... but scalar((\n2*\n3)/\n1) is in units of centimeters. Will scalar(veclen(\x3,\y3)) be in units of centimeters? – user74973 Mar 12 '18 at 03:48
  • You express \n1, \n2, and \n3 in units of centimeters. Why did you use "scalar" in the command for \n4? – user74973 Mar 12 '18 at 03:48
  • @user74973 The scaling with *2.54/72.27 is to get the value right. For example if A and B was 1cm apart, veclen(\x1,\y1) gives you 28.45pt, but veclen(\x1,\y1)*2.54/72.27 gives you 1pt. Note the pt is still there. scalar just strips pt, so you get a unitless number. – Torbjørn T. Mar 12 '18 at 08:15
  • 1
    If the distance between A and B were 1cm, veclen(\x1,\y1)*2.54/72.27 would calculate the length of line segment AB in units of centimeters. Since the location of point P is computed from the ratio |AD|*|BC|/|AB|, why do you instruct TikZ to calculate the lengths of these line segments, via \n1, \n2, and \n3, in units of centimeters? Why not just keep them in units of points? (Now, I understand your use of scalar in the calculation for n4.) – user74973 Mar 12 '18 at 14:44
  • @user74973 If you try that, you'll see that |DP| becomes rather large ... Actually though, I think I was confused by your comment where you say that P should be "at a distance from D equal to (\n2*\n3)/\n1 times the distance between C and D". That is what I have done in my code. But in your question you state that you want |DP| = (|AD|*|BC|)/|AB|, which is not the same thing. I guess that comment was wrong, so scalar isn't needed, and neither is the scaling by *2.54/72.27. Will edit my answer later tonight. – Torbjørn T. Mar 12 '18 at 19:04
  • I see that you have edited your response. I will look at it later. Thanks. (I will delete this comment.) – user74973 Mar 15 '18 at 14:00
0

Calculating the node distance : \coordinate (P) at ($(D)!{(-\AD*\BC/\AB}!(C)$);

enter image description here

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\makeatletter
\newcommand{\NodeDist}[3][\MyDist]{%
    \pgfpointdiff{\pgfpointanchor{#2}{center}}
                 {\pgfpointanchor{#3}{center}}
    % no need to use a new dimen
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    % to convert from pt to cm   
    \pgfmathparse{veclen(\pgf@xa,\pgf@ya)/28.45274}
    \global\let#1\pgfmathresult % we need a global macro    
}
\makeatother

\begin{document}
\begin{tikzpicture}

\coordinate (O) at (0,0);
\draw[dashed] (195:2.5) arc (195:160:2.5);
\draw (160:2.5) arc (160:5:2.5);
\draw[dashed] (-15:2.5) arc (-15:5:2.5);


%Chord $\overline{AB}$ is drawn.
\path (100:2.5) coordinate (A) (160:2.5) coordinate (B) (5:2.5) coordinate (C) (40:2.5) coordinate (D);
\draw (A) -- (B) -- (C) -- (D) -- cycle;
\draw (A) -- (C);
\draw (B) -- (D);


%Labels for the endpoints of the chord AB are typeset.
\draw let \p1=($(A)-(B)$), \n1={atan(\y1/\x1)}, \p2=($(A)-(D)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+(\n2+180))+180}, inner sep=0] at ($(A) +({0.5*(\n1+(\n2+180))}:0.15)$){\textit{A}};
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor=\n1, inner sep=0] at ($(B) +({\n1+180}:0.15)$){\textit{B}};
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+180}, inner sep=0] at ($(C) +(\n1:0.15)$){\textit{C}};
\draw let \p1=($(A)-(D)$), \n1={atan(\y1/\x1)}, \p2=($(C)-(D)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+(\n2+180))+180}, inner sep=0] at ($(D) +({0.5*(\n1+(\n2+180))}:0.15)$){\textit{D}};


%P is a point on the line through C and D so that D is between it and C, and |PD| = (|AD|*|BC|)/|AB|.
%\path let \p1=($(A)-(B)$), \n1={veclen(\x1,\y1)}, \p2=($(A)-(D)$), \n2={veclen(\x2,\y2)}, \p3=($(B)-(C)$), \n3={veclen(\x3,\y3)} in coordinate (P) at
%($(D)!{(-1*\n2*\n3/\n1)*1cm}!(C)$);

\NodeDist[\AD]{A}{D}
\NodeDist[\BC]{B}{C}
\NodeDist[\AB]{A}{B}

\coordinate (P) at ($(D)!{(-\AD*\BC/\AB}!(C)$);

\draw[fill] (P) circle (1.5pt);
\draw[dashed] (P) -- (D);

\end{tikzpicture}

\end{document}
Tarass
  • 16,912