标记两条射线的交点

标记两条射线的交点

我有矩形及其两条对角线的代码ABCD。我试图从相邻顶点C和绘制射线D,每条射线垂直于一条对角线,标记两条射线的交点P,并绘制一条线段,该P线段垂直于。CDCD

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


\begin{document}

\begin{tikzpicture}
\coordinate (A) at (-0.5,-0.75);
\coordinate (B) at (-0.5,0.5);
\coordinate (C) at (1,0.5);
\coordinate (D) at (1,-0.75);

\path[fill=yellow] (A) -- (B) -- (C) -- (D) -- cycle;

\path (C) -- ($(C)!1.5cm!90:(A)$);
\path (D) -- ($(D)!1.5cm!-90:(B)$);

\draw[draw=red!50, line width=0.1pt, name path=ray1] (A) -- (C);
\draw[draw=red!50, line width=0.1pt, name path=ray2] (B) -- (D);

%\coordinate [name intersections={of=ray1 and vertical,by={P}}] ;

\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]below left:$A$}] at (A) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]above left:$B$}] at (B) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]above right:$C$}] at (C) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]below right:$D$}] at (D) {};
\end{tikzpicture}
\end{document}

答案1

可能是這樣。

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


\begin{document}

\begin{tikzpicture}
\coordinate (A) at (-0.5,-0.75);
\coordinate (B) at (-0.5,0.5);
\coordinate (C) at (1,0.5);
\coordinate (D) at (1,-0.75);

\path[fill=yellow] (A) -- (B) -- (C) -- (D) -- cycle;

\path[draw,name path=ray1] (C) -- ($(C)!1.5cm!90:(A)$);
\path[draw,name path=ray2] (D) -- ($(D)!1.5cm!-90:(B)$);

\draw[draw=red!50, line width=0.1pt] (A) -- (C);
\draw[draw=red!50, line width=0.1pt] (B) -- (D);

\coordinate [name intersections={of=ray1 and ray2,by={P}}] ;

\node[circle,fill,inner sep=1.5pt,outer sep=0pt,label={right:$P$}] at (P) {};
\draw (P) -- ($(D)!(P)!(C)$);

\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]below left:$A$}] at (A) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]above left:$B$}] at (B) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]above right:$C$}] at (C) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]below right:$D$}] at (D) {};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

类似这样的?我认为我的方法与 Harish Kumar 的方法不同,所以尽管他先回答了,我还是会发帖。请注意,使用我的方法,第二个交点就是您想要的交点,因此我将第一个交点命名为 Q,这样第二个交点就是 P。

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{calc,intersections,quotes,backgrounds}

\begin{document}
  \tikzset{
    my circle/.style={outer sep=0pt, circle, fill, inner sep=1.5pt},
    my ray/.style={draw=red!50, line width=.1pt}
  }

  \begin{tikzpicture}
    \coordinate (A) at (-0.5,-0.75);
    \coordinate (B) at (-0.5,0.5);
    \coordinate (C) at (1,0.5);
    \coordinate (D) at (1,-0.75);

    \path[fill=yellow] (A) -- (B) -- (C) -- (D) -- cycle;

    \pgfmathsetmacro\myresult{atan(1.5/1.25)}
    \path [my ray, name path=ray1] (A) -- (C) -- +(-\myresult:1);
    \path [my ray, name path=ray2] (B) -- (D) -- +(\myresult:1);

    \path [name intersections={of=ray1 and ray2, by={Q,P}}] (P) node [right] {P} ;
    \draw (P) -- (C |- P);

    \node[my circle,label={[fill=white]below left:$A$}] at (A) {};
    \node[my circle,label={[fill=white]above left:$B$}] at (B) {};
    \node[my circle,label={[fill=white]above right:$C$}] at (C) {};
    \node[my circle,label={[fill=white]below right:$D$}] at (D) {};
  \end{tikzpicture}
\end{document}

射线和交点

答案3

对于那些感兴趣的人,这是一个MetaPost解决方案,用LuaLaTeX进行处理。

交点 P 是通过以下指令计算的,利用intersectionpoint两条路径之间 MetaPost 的便捷运算符。

P = (C--A) rotatedaround (C,90) intersectionpoint (D--B) rotatedaround (D,-90);

过 P 点垂直于 CD 的线段,可简单地通过将 P 点连接至线段 CD 的中点来获得。

Q = .5[C,D]; … draw P--Q; 

我还添加了直角标记,anglebetween这要归功于 MetaPost 的宏元乐趣格式。

\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
  \mplibsetformat{metafun}
  \mplibtextextlabel{enable}
\begin{document}
  \begin{mplibcode}
    u := 2cm; pair A, B, C, D, P, Q; 
    A = u*(-.5,-.75); B = u*(-.5,.5); C = u*(1,.5); D = u*(1,-.75); Q = .5[C,D];
    path rectangle; rectangle = A--B--C--D--cycle;
    P = (C--A) rotatedaround (C,90) intersectionpoint (D--B) rotatedaround (D,-90);
    beginfig(1);
      fill rectangle withcolor yellow; 
      pickup pencircle scaled .1bp;
      drawoptions(withcolor red);
      draw B--D; draw A--C;
      draw C -- 1.5[C,P]; draw D -- 1.5[D,P];
      drawoptions(withcolor black);
      freelabeloffset := 5bp;
      forsuffixes M = A, B, C, D, P:
        drawdot M withpen pencircle scaled 3bp;
        freelabel("$" & str M & "$", M, center rectangle);
      endfor
      draw P--Q;
      anglemethod := 2; anglelength := 4bp;
      draw anglebetween(C--A, C--P, "");
      draw anglebetween(D--B, D--P, "");
      draw anglebetween(Q--C, Q--P, "");
    endfig;
  \end{mplibcode}
\end{document}

在此处输入图片描述

相关内容