旧答案

旧答案

我有四边形 ABCD 内接于一个圆。我要P在通过 的直线上找到一个点CD使得D位于它和C之间

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

绘制的长度DP太长。我定位的代码有什么问题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}

答案1

实际上,你问的是两个完全不同的问题。要定位P|DP| = (|AD|*|BC|)/|AB|你只需要从*1cm代码中删除,即

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

并不是

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

原因是\n2*\n3/\n1已经是长度了,在 中pt,并且打击乐说,因为计算结果pgf也会转换1cmpt。因此,您得到的长度是 28.45 倍,因为 1cm 约为 28.45pt。

要查看此内容,您可以像这样打印出节点中的值

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

(注意aligned环境要求\usepackage{amsmath}

结果如下:

在此处输入图片描述

旧答案

你的评论你问了一个不同的问题:

P如果我想要位于通过 的线上C,并且D距离 的距离D等于乘以和(\n2*\n3)/\n1之间的距离,那么命令是什么?CD

有几件事需要考虑。首先,veclen将给出 的长度pt,因为\xN/\yN将在 中pt。因此,由于图表的其余部分使用cm,因此您需要缩放结果。我倾向于只记住 1in = 72.27pt = 2.54cm,因此乘以 2.54/72.27,但这相当于除以约 28.45。(另请参阅以 mm 表示的各种单位 (ex、em、in、pt、bp、dd、pc) 是什么?

其次,除非另有说明,否则\nN无论如何都会返回长度pt,因此您需要使用scalar函数来去除单位。这是必要的,因为使用($(a)!X!(b)!$)语法,X可以是长度或因子。您需要一个因子。

代码输出

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

答案2

计算节点距离: \coordinate (P) at ($(D)!{(-\AD*\BC/\AB}!(C)$);

在此处输入图片描述

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

相关内容