我必须用 tikz 绘制这个图表

我必须用 tikz 绘制这个图表

如何用 TikZ 绘制此图形?

在此处输入图片描述

答案1

Voronoi 图的点是虚线的顶点。外部点被命名A为 ,I两个粗点被命名为KL。通过将裁剪后的图像放在背景中并在其上放置网格,可以从图像中提取位置。最终文档不应包含网格,因此可以在\gridtrue开发阶段启用它。

每个虚线三角形都是单独绘制的。外心坐标的计算公式为维基百科并以三角形的三个点来命名外心。

由于三角形互相接触,因此在宏中会记住绘制的虚线,以避免绘制两次相同的线。

虚线的中点以线的两个端点命名。然后在三角形内绘制实线。

外部超出线也是通过定义它们预先跨越的线来绘制的。

方块的位置也需要一些计算,因为它们设置在虚线和实线的交叉处。TikZ 库intersections可以提供帮助。

完整示例:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}
\usepackage{graphicx}
\newif\ifgrid
%\gridtrue

\makeatletter
\newcommand*{\Triangle}[3]{%
  \DashLine{#1}{#2}%
  \DashLine{#2}{#3}%
  \DashLine{#3}{#1}%
  \coordinate (#1#2) at ($(#1)!.5!(#2)$);
  \coordinate (#2#3) at ($(#2)!.5!(#3)$);
  \coordinate (#3#1) at ($(#3)!.5!(#1)$);
  % https://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates_2
  \draw[red, thick, fixed point arithmetic] let
    \p{A}=(#1),
    \p{B}=(#2),
    \p{C}=(#3),
    \n{D}={%
      2 * (
        \x{A}*(\y{B}-\y{C}) + \x{B}*(\y{C}-\y{A}) + \x{C}*(\y{A}-\y{B})
      )},
    \n{x}={%
      (
        (\x{A}*\x{A} + \y{A}*\y{A}) * (\y{B}-\y{C}) +
        (\x{B}*\x{B} + \y{B}*\y{B}) * (\y{C}-\y{A}) +
        (\x{C}*\x{C} + \y{C}*\y{C}) * (\y{A}-\y{B})
      ) / \n{D}},
    \n{y}={%
      (
        (\x{A}*\x{A} + \y{A}*\y{A}) * (\x{C}-\x{B}) +
        (\x{B}*\x{B} + \y{B}*\y{B}) * (\x{A}-\x{C}) +
        (\x{C}*\x{C} + \y{C}*\y{C}) * (\x{B}-\x{A})
      ) / \n{D}}
    in
     (\n{x}, \n{y}) coordinate (#1#2#3)
      (#1#2#3)
      \@ifundefined{L@#1#2}{%
        -- (#1#2)%
      }{%
        -- ($(#1#2)!-15pt!(#1#2#3)$)%
      }
      (#1#2#3) -- (#2#3)
      (#1#2#3) -- (#3#1)
  ;%
}
\newcommand*{\DashLine}[2]{%
  \@ifundefined{dd@#1#2}{%
    \draw[densely dashed, blue] (#1) -- (#2);%
    \global\expandafter\let\csname dd@#1#2\endcsname=1%
    \global\expandafter\let\csname dd@#2#1\endcsname=1%
  }{}%
}
\newdimen\dimSq
\setlength{\dimSq}{3pt}
\newcommand*{\Square}[3]{%
  \draw
    ($(#1)!#2!(#3)$) coordinate (sq1)
    ($(sq1)!\dimSq!0:(#3)$) coordinate (sq2)
    ($(sq2)!\dimSq!-90:(#3)$) coordinate (sq3)
    ($(sq1)!\dimSq!-90:(#3)$) coordinate (sq4)
    (sq1) -- (sq2) -- (sq3) -- (sq4) -- cycle
  ;%
}
\newcommand*{\SquareM}[4]{%
  \path[name path=lineA] (#1) -- (#2);
  \path[name path=lineB] (#3) -- (#4);
  \draw[
    name intersections={of=lineA and lineB, name=cross},
  ]
    ($(cross-1)!\dimSq!0:(#2)$) coordinate (sq2)
    ($(sq2)!\dimSq!90:(#2)$) coordinate (sq3)
    ($(cross-1)!\dimSq!90:(#2)$) coordinate (sq4)
    (cross-1) -- (sq2) -- (sq3) -- (sq4) -- cycle
  ;
}
\makeatother

\begin{document}
\setlength{\unitlength}{.75mm}
\begin{tikzpicture}[x=\unitlength, y=\unitlength]

  \ifgrid
    \node[above right, inner sep=0pt]
      (img) {\includegraphics[width=100\unitlength]{D27KN-crop.png}};
    \draw[ultra thin, gray, step=1\unitlength]
      (img.south west) grid (img.north east);
    \draw[thin, red, step=10\unitlength]
      (img.south west) grid (img.north east);
  \fi

  \coordinate (A) at (94, 62);
  \coordinate (B) at (73, 86);
  \coordinate (C) at (38, 82);
  \coordinate (D) at (15, 61);
  \coordinate (E) at ( 7, 34);
  \coordinate (F) at (22, 10);
  \coordinate (G) at (48,  1);
  \coordinate (H) at (76,  8);
  \coordinate (I) at (86, 27);
  \coordinate (K) at (62, 53);
  \coordinate (L) at (46, 27);

  \fill[radius=1pt] \foreach \P in {A, ..., I} {(\P) circle[]};
  \fill[radius=2pt] (K) circle[] (L) circle[];

  \foreach \L in {AB, BC, CD, DE, EF, FG, GH, HI, IA}
  {\global\expandafter\let\csname L@\L\endcsname=1 }

  \foreach \T in {ABK, BCK, CDK, DEL, EFL, FGL, GHL, HIL, IAK, LKD, LIK}
  {\expandafter\Triangle\T}

  \path
    (K)   -- node[pos=.75] {$K$} (ABK)
    (K)   -- node[pos=.35] {$\mathbf{x}_K$} (IAK)
    (LK)  -- node[pos=.55] {$S$} (I)
    (L)   -- node[pos=.3] {$\mathbf{x}_L$} (GH)
    (L)   -- node[pos=.4] {$L$} (EF)
    (LKD) -- node[pos=.4, above] {$e$} (LIK)
  ;
  \draw[-{LaTeX}]
    ($(LKD)!.65!(LIK)$) coordinate (tmp)
    (tmp) -- ($(tmp)!15pt!90:(LKD)$)
    node[below right, yshift=1ex] {$\mathbf{n}_{K,e}$}
  ;
  \Square{LKD}{.65}{LIK}
  \SquareM{LIK}{IAK}IK
  \SquareM{IAK}{ABK}AK
  \SquareM{ABK}{BCK}BK
  \SquareM{BCK}{CDK}CK
  \SquareM{CDK}{LKD}DK
  \path[lightgray, node font=\scriptsize]
    \foreach \P/\N in {
      A/right,
      B/above,
      C/above left,
      D/left,
      E/left,
      F/below left,
      G/below,
      H/below right,
      I/right%
    } { (\P) node[\N] {\P} }
  ;

\end{tikzpicture}
\end{document}

结果

答案2

使用xelatex或运行latex->dvips->ps2pdf

\documentclass{scrartcl}
\usepackage{pst-eucl,pst-math}
\begin{document}

\psset{unit=1mm}
\begin{pspicture}(100,100)
\pstGeonode[PosAngle={10,45,90,110,170,200,-90,-45,0,-90,90}]%
  (94, 62){A}(73, 86){B}(38, 82){C}(15, 61){D}( 7, 34){E}%
  (22, 10){F}(48,  1){G}(76,  8){H}(86, 27){I}(62, 53){K}(46, 27){L}
\end{pspicture}
\psset{linestyle=dashed,linecolor=blue}
\pspolygon(A)(B)(C)(D)(E)(F)(G)(H)(I)
\psline(B)(K)(L)(G)\psline(H)(L)(E)\psline(I)(L)(D)\psline(I)(K)(D)
\psline(C)(K)(A)\psline(L)(F)
\psset{PointSymbol=none,PointName=none,linestyle=none}
\pstCircleABC{A}{B}{K}{M0} \pstCircleABC{B}{C}{K}{M1}% Mx intersection point
\pstCircleABC{C}{D}{K}{M2} \pstCircleABC{D}{L}{K}{M3}
\pstCircleABC{D}{E}{L}{M4} \pstCircleABC{E}{F}{L}{M5}
\pstCircleABC{F}{G}{L}{M6} \pstCircleABC{G}{H}{L}{M7}
\pstCircleABC{H}{I}{L}{M8} \pstCircleABC{I}{K}{L}{M9}
\pstCircleABC{I}{A}{K}{M10}
\psset{linestyle=solid,linecolor=red,linewidth=1pt}
\pspolygon(M9)(M10)(M0)(M1)(M2)(M3)
\psline(M3)(M4)(M5)(M6)(M7)(M8)(M9)
\pstMiddleAB{A}{B}{AB}\pstMiddleAB{B}{C}{BC}
\pstMiddleAB{C}{D}{CD}\pstMiddleAB{D}{E}{DE}
\pstMiddleAB{E}{F}{EF}\pstMiddleAB{F}{G}{FG}
\pstMiddleAB{G}{H}{GH}\pstMiddleAB{H}{I}{HI}
\pstMiddleAB{I}{A}{IA}
\psset{nodesepA=-10}
\pcline(AB)(M0)\pcline(BC)(M1)\pcline(CD)(M2)
\pcline(DE)(M4)\pcline(EF)(M5)\pcline(FG)(M6)
\pcline(GH)(M7)\pcline(HI)(M8)\pcline(IA)(M10)
\uput[-80](L){$x_L$}\uput[190](K){$x_K$}
\end{document}

在此处输入图片描述

答案3

使用\usetikzlibrary{intersections,calc}

%\usetikzlibrary{intersections,calc}
\begin{tikzpicture}
\coordinate[label=left:$X_k$](O) at (0,0);
\coordinate[label=$A2$](A2) at ($(O)+(10:3)$);
\coordinate[label=$A3$](A3) at ($(O)+(45:3)$);
\coordinate[label=$A4$](A4) at ($(O)+(100:3)$);
\coordinate(C5) at ($(O)+(160:4)$);
\coordinate[label=left:$X_L$](K) at ($(O)+(220:3)$);
 \coordinate(C1) at ($(O)+(-60:4)$);
 \coordinate(B1) at ($(K)+(110:4)$);
 \coordinate[label=$B2$](B2) at ($(K)+(170:3)$);
 \coordinate[label=$B3$](B3) at ($(K)+(220:3)$);
 \coordinate[label=$B4$](B4) at ($(K)+(-90:3)$);
 \coordinate[label=$B5$](B5) at ($(K)+(-45:3.5)$);
 \coordinate(B7) at ($(K)+(-10:2)$);
 \fill(O)circle (1mm);
 \fill(K)circle (1mm);
 \coordinate[label=$A5$] (A5) at (intersection cs:first line={(O)--(C5)}, second line={(K)--(B1)});
 \coordinate[label=$A5$] (B1) at (intersection cs:first line={(O)--(C5)}, second line={(K)--(B1)});
 \coordinate[label=$A1$] (A1) at (intersection cs:first line={(O)--(C1)}, second line={(K)--(B7)});
 \coordinate(B6) at (intersection cs:first line={(O)--(C1)}, second line={(K)--(B7)});
 \begin{scope}[dashed,blue]
 \draw (A1)--(A2)--(A3)--(A4)--(A5)--(B2)--(B3)--(B4)--(B5)--cycle;
\foreach \x in {1,2,3,4,5}
  {
 \draw (O)--(A\x);
}
\foreach \x in {1,2,3,4,5,6}
  {
 \draw (K)--(B\x);
}
 \draw (O)--(K);
\end{scope}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \foreach \i in {1,2,3,4,5}
 {
\coordinate(M\i) at ($(O)!0.5!(A\i)$);
 }
 \foreach \i in {1,2,3,4,5,6}
 {
 \coordinate(X\i) at ($(K)!0.5!(B\i)$);
 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \foreach \i in {1,2,3,4,5}
 {
 \coordinate(L\i) at  ($(M\i)!2cm!90:(A\i)$);
}
 \coordinate (T1) at (intersection cs:first line={(M1)--(L1)}, second line={(M2)--(L2)});
 \coordinate (T2) at (intersection cs:first line={(M2)--(L2)}, second line={(M3)--(L3)});
 \coordinate (T3) at (intersection cs:first line={(M3)--(L3)}, second line={(M4)--(L4)});
 \coordinate (T4) at (intersection cs:first line={(M4)--(L4)}, second line={(M5)--(L5)});

 \foreach \i in {1,2,3,4,5,6}
 {
 \coordinate(H\i) at  ($(X\i)!2cm!90:(B\i)$);
}
\coordinate (T5) at (intersection cs:first line={(M5)--(L5)}, second line={(X1)--(H1)});
\coordinate (T6) at (intersection cs:first line={(X1)--(H1)}, second line={(X2)--(H2)});
\coordinate (T7) at (intersection cs:first line={(X2)--(H2)}, second line={(X3)--(H3)});
\coordinate (T8) at (intersection cs:first line={(X3)--(H3)}, second line={(X4)--(H4)});
\coordinate (T9) at (intersection cs:first line={(X4)--(H4)}, second line={(X5)--(H5)});
\coordinate (T10)at (intersection cs:first line={(X5)--(H5)}, second line={(X6)--(H6)});
\coordinate (T11)at (intersection cs:first line={(M1)--(L1)}, second line={(X6)--(H6)});
\begin{scope}[red,very thick]
\draw(T1)--(T2)--(T3)--(T4)--(T5)--(T6)--(T7)--(T8)--(T9)--(T10)--(T11)--cycle;
\draw(T5)--(T11);
\coordinate (E1) at ($(A1)!0.5!(A2)$);
\coordinate (E2) at ($(A2)!0.5!(A3)$);
\coordinate (E3) at ($(A3)!0.5!(A4)$);
\coordinate (E4) at ($(A4)!0.5!(A5)$);
\coordinate (E5) at ($(A5)!0.5!(B2)$);
\coordinate (E6) at ($(B2)!0.5!(B3)$);
\coordinate (E7) at ($(B3)!0.5!(B4)$);
\coordinate (E8) at ($(B4)!0.5!(B5)$);
\coordinate (E9) at ($(B5)!0.5!(B6)$);
\draw(T1)--($(T1)!2!(E1)$);
\draw(T2)--($(T2)!2!(E2)$);
\draw(T3)--($(T3)!2!(E3)$);
\draw(T4)--($(T4)!2!(E4)$);
\draw(T6)--($(T6)!2!(E5)$);
\draw(T7)--($(T7)!2!(E6)$);
\draw(T8)--($(T8)!2!(E7)$);
\draw(T9)--($(T9)!2!(E8)$);
\draw(T10)--($(T10)!2!(E9)$);
\end{scope}
\node  at (0.5,1) {$K$};
\node  at (-3,-1) {$L$};
 \coordinate(S) at  ($(T11)!.40!(T5)$);
 \coordinate(S1) at  ($(S)!1cm!90:(T5)$);
\draw[->,thick](S)--node[below,sloped]{$n_{k,e}$}(S1);

\end{tikzpicture}

在此处输入图片描述

相关内容