如何在 3d-tikz 中複製圖案?

如何在 3d-tikz 中複製圖案?

我目前有一個“細胞”,如下所示:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz-3dplot}
\usetikzlibrary{patterns,arrows,positioning,3d,calc,fadings,shapes,decorations.markings,arrows.meta}
\usepackage{tikz,times,amsmath}
\begin{document}
\tdplotsetmaincoords{85}{20}
\begin{tikzpicture}[yscale=2,xscale=2,line width=0.5pt, tdplot_main_coords]
    \coordinate (A) at (0,0,0);
    \coordinate (B) at (1,0,0);
    \coordinate (C) at (2,0,0);
    \coordinate (D) at (1,0,1);
    \coordinate (X) at (0,0,-1);
    \coordinate (H) at (1,0,-1);
    \coordinate (Y) at (2,0,1);
    
    \coordinate (A1) at (2,0,2);
    \coordinate (B1) at (2,1,2);
    \coordinate (C1) at (0,1,2);
    \coordinate (D1) at (0,0,2);
    \coordinate (E) at (1,-0.87,0.5);
    \coordinate (X4) at (0,-0.87,0.5);
    \coordinate (F) at (1,0.87,0.5);
    \coordinate (X5) at (0,0.87,0.5);
    \coordinate (X6) at (1,-0.87,1.5);
    \coordinate (X7) at (1,0.87,1.5);
    \coordinate (G) at (1,-0.87,-0.5);
    \coordinate (I) at (1,-1.73,0);
    \coordinate (Y2) at (1,-0.87,-1.5);
    \coordinate (Y3) at (2,-0.87,-0.5);
    \coordinate (Y4) at (2,0.87,-0.5);
    \coordinate (Y5) at (1,0.87,-0.5);
    \coordinate (J) at (1,1.73,0);
    \coordinate (Y6) at (1,0.87,-1.5);
    \coordinate (K) at (2,0,-1);
    \coordinate (M) at (2,1,1);
    \coordinate (N) at (1,0,1);
    \draw[rounded corners=0.05pt](A)circle (0.25pt)node[left=-2pt]{$A$}
    (B)circle (0.25pt)node[below]{$B$}
    (C)circle (0.25pt)node[right]{$C$}
    (D)circle (0.25pt)node[left]{$D$}
    (E)circle (0.25pt)node[right]{$E$}
    (F)circle (0.25pt)node[right]{$F$}
    (G)circle (0.25pt)node[left]{$G$}
    (H)circle (0.25pt)node[right]{$H$}
    (I)circle (0.25pt)node[left]{$I$}
    (J)circle (0.25pt)node[right]{$J$}
    (X)--(A)--(X4)--(E)--(I)--(G)--(B)--(E)--(X6)--(D)--(B)
    (X7)--(D)
    (G)--(Y3)--(C)--(B)--(G)--(Y2)--(H)
    (Y4)--(C)--(Y)--(D);
    \draw[thin,dash pattern=on 2pt off 2pt]
    (A)--(B)--(F)--(X5)--(A)
    (X)--(H)--(B)--(F)--(J)--(Y5)--(Y4)
    (H)--(Y6)--(Y5)
    (F)--(X7)
    (B)--(Y5);
\end{tikzpicture}
\end{document}

我想要實現的是透過將原始 $A$ 頂點轉換為 $C$ 來「複製」單元格(將「單元格」沿 $x$ 軸向右平移 2 個單位)。有沒有簡單的方法,不用翻譯後直接列出所有要點?標籤不是必需的。

答案1

我不確定結果應該是什麼樣子,但正如我在評論中建議的那樣,\pic如果您想重複使用 a 的一部分,您可以使用 a tikzpicture

在下面的程式碼範例中,我只是從您的程式碼中獲取了完整的繪圖並將其設為\pic.我放置了其中兩個,\pic以便第二個的座標與第一個的A座標位置相符。C請注意,由於範圍的限制,您需要\pic單獨套用轉換。

\documentclass[border=10pt]{standalone}
\usepackage{tikz, tikz-3dplot}

\tikzset{
    pics/my cell/.style={
        code={
            \coordinate (A) at (0,0,0);
            \coordinate (B) at (1,0,0);
            \coordinate (C) at (2,0,0);
            \coordinate (D) at (1,0,1);
            \coordinate (X) at (0,0,-1);
            \coordinate (H) at (1,0,-1);
            \coordinate (Y) at (2,0,1);
            \coordinate (A1) at (2,0,2);
            \coordinate (B1) at (2,1,2);
            \coordinate (C1) at (0,1,2);
            \coordinate (D1) at (0,0,2);
            \coordinate (E) at (1,-0.87,0.5);
            \coordinate (X4) at (0,-0.87,0.5);
            \coordinate (F) at (1,0.87,0.5);
            \coordinate (X5) at (0,0.87,0.5);
            \coordinate (X6) at (1,-0.87,1.5);
            \coordinate (X7) at (1,0.87,1.5);
            \coordinate (G) at (1,-0.87,-0.5);
            \coordinate (I) at (1,-1.73,0);
            \coordinate (Y2) at (1,-0.87,-1.5);
            \coordinate (Y3) at (2,-0.87,-0.5);
            \coordinate (Y4) at (2,0.87,-0.5);
            \coordinate (Y5) at (1,0.87,-0.5);
            \coordinate (J) at (1,1.73,0);
            \coordinate (Y6) at (1,0.87,-1.5);
            \coordinate (K) at (2,0,-1);
            \coordinate (M) at (2,1,1);
            \coordinate (N) at (1,0,1);
            \draw[rounded corners=0.05pt]
                (A) circle[radius=0.25pt] node[left=-2pt]{$A$}
                (B) circle[radius=0.25pt] node[below]{$B$}
                (C) circle[radius=0.25pt] node[right]{$C$}
                (D) circle[radius=0.25pt] node[left]{$D$}
                (E) circle[radius=0.25pt] node[right]{$E$}
                (F) circle[radius=0.25pt] node[right]{$F$}
                (G) circle[radius=0.25pt] node[left]{$G$}
                (H) circle[radius=0.25pt] node[right]{$H$}
                (I) circle[radius=0.25pt] node[left]{$I$}
                (J) circle[radius=0.25pt] node[right]{$J$}
                (X)--(A)--(X4)--(E)--(I)--(G)--(B)--(E)--(X6)--(D)--(B)
                (X7)--(D)
                (G)--(Y3)--(C)--(B)--(G)--(Y2)--(H)
                (Y4)--(C)--(Y)--(D);
            \draw[thin, dash pattern=on 2pt off 2pt]
                (A)--(B)--(F)--(X5)--(A)
                (X)--(H)--(B)--(F)--(J)--(Y5)--(Y4)
                (H)--(Y6)--(Y5)
                (F)--(X7)
                (B)--(Y5);
        }
    }
}

\begin{document}
\tdplotsetmaincoords{85}{20}
\begin{tikzpicture}[scale=2, line width=0.5pt, tdplot_main_coords]

\pic[scale=2] at (0,0,0) {my cell};

\pic[scale=2] at (2,0,0) {my cell};

\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容