指示线段的长度

指示线段的长度

我想在某个图中标记四条线段的长度。在图中,线段的长度PQ应标记为a,线段的长度QS应标记为b,线段的长度PR应标记为``c,线段的长度RT应标记为d

的标签a可以放置在与 平行且位于 下方的线段的中间k(包含点PQR)。我在此网站上看到该命令\draw[|<->|]用于此显示。 的标签a也可以放置在{绘制在线段 下方的下方PQ。我在手册中没有看到TikZ如何执行此操作。

另外,我希望将线段或{用于指示线段长度PQPR放置在图的顶部 - 这样它周围会有一些空白。如果不将线段或放置在顶部,轴和线\ell_{1}就会发生干扰。\ell_{2}{

\documentclass{amsart}
\usepackage{tikz}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}


\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-13,xmax=13,samples=2,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=18,
    restrict y to domain=-10:18,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-13:13,blue] {x + 3} node[below, pos=0.1,font=\footnotesize]{$j$};
\addplot[latex-latex,samples=2,domain=-13:13,blue] {0.5*x + 1} node[above, pos=0.1,font=\footnotesize]{$k$};
\addplot[latex-latex,samples=2,domain=-4:10,blue] {2*x - 2} node[above left, pos=0.05,font=\footnotesize]{$\ell_{1}$};
\addplot[latex-latex,samples=2,domain=-1:13,blue] {2*x - 8} node[above left, pos=0.05,font=\footnotesize]{$\ell_{2}$};
\draw [fill] (-4,-1) circle [radius=1pt] node[below]{$P$};
\draw [fill] (2,2) circle [radius=1pt] node[below right]{$Q$};
\draw [fill] (6,4) circle [radius=1pt] node[below right]{$R$};
\draw [fill] (5,8) circle [radius=1pt] node[above left]{$S$};
\draw [fill] (11,14) circle [radius=1pt] node[above left]{$T$};
\end{axis}
\end{tikzpicture}
\hspace*{\fill}
\vskip0.25in

\end{document}

答案1

这是大括号内的版本。

\documentclass{amsart}
\usepackage{tikz}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{intersections,decorations.pathreplacing,positioning}

\begin{document}


\noindent 
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-13,xmax=13,samples=2,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=18,
    restrict y to domain=-10:18,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-13:13,blue,name path = A] {x + 3} node[below, pos=0.1,font=\footnotesize]{$j$};
\addplot[latex-latex,samples=2,domain=-13:13,blue,name path = B] {0.5*x + 1} node[above, pos=0.1,font=\footnotesize]{$k$};
\addplot[latex-latex,samples=2,domain=-4:10,blue,name path = C] {2*x - 2} node[above left, pos=0.05,font=\footnotesize]{$\ell_{1}$};
\addplot[latex-latex,samples=2,domain=-1:13,blue,name path = D] {2*x - 8} node[above left, pos=0.05,font=\footnotesize]{$\ell_{2}$};
\path[name intersections={of=A and B, by={a}}]
  node[fill,circle,inner sep=1pt,label=below:$P$] at (a) {};
\path[name intersections={of=B and C, by={b}}]
  node[fill,circle,inner sep=1pt,label=below right:$Q$] at (b) {};
\path[name intersections={of=B and D, by={c}}]
  node[fill,circle,inner sep=1pt,label=below right:$R$] at (c) {};
\path[name intersections={of=A and C, by={d}}]
  node[fill,circle,inner sep=1pt,label=above left:$S$] at (d) {};
\path[name intersections={of=A and D, by={e}}]
  node[fill,circle,inner sep=1pt,label=above left:$T$] at (e) {};

\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (a)  -- node[below right=3pt and -1pt]{a} (b) ;
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt}] (a)  -- node[above left=3pt and -1pt]{c} (c) ;
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (b)  -- node[right=3pt]{b} (d) ;
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (c)  -- node[right=3pt]{d} (e) ;
\end{axis}
\end{tikzpicture}

\end{document}

我已经使用了intersections库,因此无需手动猜测交点。

在此处输入图片描述

\draw[latex-latex,blue] (a)  -- node[fill=white,inner ysep=0pt]{a} (b) ;
\draw[latex-latex,blue] ([shift={(-3pt,5pt)}]a)  -- node[fill=white,inner sep=1.8pt]{c} ([shift={(-3pt,5pt)}]c) ;
\draw[latex-latex,blue] (b)  -- node[fill=white]{b} (d) ;
\draw[latex-latex,blue] (c)  -- node[fill=white]{d} (e) ;

在此处输入图片描述

答案2

尝试使用 MetaPost 的“括号版本”。希望带箭头的版本能尽快推出。

mkbrace这里括号内的宏是从该包中借用的,mfpic由其当前维护者 Dan Luecking 设计。

使用LuaLaTeX进行排版。

\documentclass[12pt, border=5mm]{standalone}
\usepackage{luamplib}
  \mplibsetformat{metafun}
  \mplibtextextlabel{enable}
\begin{document}
  \begin{mplibcode}
    % Creates a brace between points S and E with cusp placed in C
    % Borrowed from the mfpic package, by Dan Luecking
    vardef mkbrace (expr S, C, E) =
      save R_, U_, V_, Z_;
      pair U_, V_, Z_[];
      U_ := unitvector (E-S);
      V_ := U_ rotated 90;
      R_ := 0.5*(C-S) dotprod V_;
      if R_ = 0:
        S--C
      else:
        if R_ < 0 :  V_ := -V_; R_ := -R_;  fi
        V_ := R_*V_; U_ := R_*U_;
        Z_1 := S + V_ + U_;
        Z_2 := C - V_ - U_;
        Z_3 := C - V_ + U_;
        Z_4 := E + V_ - U_;
        S{V_}..{U_}Z_1--Z_2{U_}..{V_}C{-V_}..{U_}Z_3--Z_4{U_}..{-V_}E
      fi
    enddef;

    hcusp := 2mm;
    vardef drawbrace (expr p, str) =
      save S, C, E; pair S, C, E;
      S = point 0 of p; E = point 1 of p; 
      C = .5[S,E] shifted (hcusp*unitvector((E-S) rotated 90));
      draw mkbrace(S, C, E);
      freelabeloffset := 1bp;
      freelabel(str, C, .5[S, E]);
    enddef;

    vardef bigline(text f) =
      (xmin, hide(x := xmin) f) -- (xmax, hide(x := xmax) f)
    enddef;

    u := .5cm;
    xmin := -13; xmax := 13; ymin := -10; ymax := 18;

    path sup_border; sup_border = (xmin, ymax) -- (xmax, ymax);
    path inf_border; inf_border = (xmin, ymin) -- (xmax, ymin);

    beginfig(1);
      drawarrow (xmin*u, 0) -- (xmax*u, 0); label.bot("$x$", (xmax*u, 0));
      drawarrow (0, ymin*u) -- (0, ymax*u); label.lft("$y$", (0, ymax*u));

      path PQ, PS, QS, RT;
      PQ = bigline(.5x + 1) scaled u; 
      PS = bigline(x + 3) scaled u;
      QS = (bigline(2x - 2) cutbefore inf_border cutafter sup_border) scaled u;
      RT = (bigline(2x - 8) cutbefore inf_border cutafter sup_border) scaled u;

      pair P, Q, R, S, T;
      P = PQ intersectionpoint PS;
      Q = PQ intersectionpoint QS;
      R = PQ intersectionpoint RT;
      S = PS intersectionpoint QS;
      T = PS intersectionpoint RT;

      drawoptions(withcolor blue);
      for line = PQ, PS, QS, RT: draw line; endfor;
      labeloffset := 5bp;
      label.top("$k$", point cm on PQ);
      label.bot("$j$", point cm on PS);
      label.lft("$\ell_1$", point 1cm on QS);
      label.lft("$\ell_2$", point 1cm on RT);

      drawoptions();
      for point = P, Q, R, S, T:
        drawdot point withpen pencircle scaled 3bp;
      endfor;
      labeloffset := 3bp;
      label.bot("$P$", P); label.lrt("$Q$", Q); label.bot("$R$", R);
      label.ulft("$S$", S); label.ulft("$T$", T);

      hcusp := -4mm;
      drawbrace (P--Q, "$a$"); drawbrace (Q--S, "$b$"); drawbrace (R--T, "$d$");
      hcusp := 4mm;
      drawbrace (P--R, "$c$");
    endfig;
  \end{mplibcode}  
\end{document}

在此处输入图片描述

现在有了箭头(受到 Harish Kumar 的回答的启发)。

\documentclass[12pt, border=2bp]{standalone}
\usepackage{luamplib}
  \mplibsetformat{metafun}
  \mplibtextextlabel{enable}
\begin{document}
  \begin{mplibcode}
    def clear(expr pict) = unfill bbox pict; draw pict; enddef;

    vardef drawdoublearrow(expr pat, str) =
      save A, B, v; pair A, B; 
      A = point 0 of pat; B = point 1 of pat;
      drawdblarrow A--B;
      clear(thelabel(str, .5[A,B]));
    enddef;

    hoffset := 3mm;
    vardef drawbarends(expr pat, str) =
        save A, B, v; pair A, B, v; 
        v = hoffset*(unitvector(point 1 of pat - point 0 of pat) rotated 90);
      A = point 0 of pat shifted v;
      B = point 1 of pat shifted v;
        drawdblarrow A -- B;
        for M = A, B:
          draw M+v -- M-v;
        endfor;
        clear(thelabel(str, .5[A,B]));
    enddef;

    vardef bigline(text f) =
      (xmin, hide(x := xmin) f) -- (xmax, hide(x := xmax) f)
    enddef;

    u := .5cm;
    xmin := -13; xmax := 13; ymin := -10; ymax := 18;

    path sup_border; sup_border = (xmin, ymax) -- (xmax, ymax);
    path inf_border; inf_border = (xmin, ymin) -- (xmax, ymin);

    beginfig(1);
      drawarrow (xmin*u, 0) -- (xmax*u, 0); label.bot("$x$", (xmax*u, 0));
      drawarrow (0, ymin*u) -- (0, ymax*u); label.lft("$y$", (0, ymax*u));

      path PQ, PS, QS, RT;
      PQ = bigline(.5x + 1) scaled u; 
      PS = bigline(x + 3) scaled u;
      QS = (bigline(2x - 2) cutbefore inf_border cutafter sup_border) scaled u;
      RT = (bigline(2x - 8) cutbefore inf_border cutafter sup_border) scaled u;

      pair P, Q, R, S, T;
      P = PQ intersectionpoint PS;
      Q = PQ intersectionpoint QS;
      R = PQ intersectionpoint RT;
      S = PS intersectionpoint QS;
      T = PS intersectionpoint RT;

      drawoptions(withcolor blue);
      for line = PQ, PS, QS, RT: draw line; endfor;
      labeloffset := 5bp;
      label.top("$k$", point cm on PQ);
      label.bot("$j$", point cm on PS);
      label.lft("$\ell_1$", point 1cm on QS);
      label.lft("$\ell_2$", point 1cm on RT);

      drawoptions();
      labeloffset := 3bp;
      label.bot("$P$", P); label.lrt("$Q$", Q); label.bot("$R$", R);
      label.ulft("$S$", S); label.ulft("$T$", T);

      drawdoublearrow (P--Q, "$a$"); drawdoublearrow (Q--S, "$b$"); 
      drawdoublearrow (R--T, "$d$"); drawbarends(P--R, "$c$");
    endfig;
  \end{mplibcode}  
\end{document}

在此处输入图片描述

相关内容