TikZ 中的叠加图

TikZ 中的叠加图

我想连接标记为 (1)、b、abc 和 ac 的顶点,但无法成功。如果您能指出我做错了什么以及解决方案是什么,我将不胜感激。谢谢

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale = 4, fill opacity = 1.0, thick,
                        line cap = round, line join = round]
    %% Define coordinate labels.
    % t(op) and b(ottom) layers
    \path \foreach \layer/\direction in {b/{0, 0, 0}, t/{0, 1, 0}} {
        (\direction)
        \foreach \point/\label in {{0, 0, 0}/ll, {1, 0, 0}/lr, {1, 0, -1}/ur, {0, 0, -1}/ul} {
            +(\point) coordinate (\layer\label)
        }
        ($(\layer ll)!0.5!(\layer ur)$) coordinate (\layer md)
    };



    % Put text next to the labels as requested.
    % Funilly enough we need to set fill opacity to 1.
    \draw \foreach \text/\label/\anchor in {%
        $\left(1\right)$/bll/east,
        $b$/bul/east,
        $c$/tll/east,
        $bc$/tul/east,
        $a$/blr/west,
        $ab$/bur/west,
        $ac$/tlr/west,
        $abc$/tur/west} {
        (\label) node[anchor=\anchor, fill opacity = 1] {\text}
    };
    % Draw  cube.
    \fill (0, 0, -1) circle (0.5pt);
    \foreach \direction in {(0, 0, 1), (0, 1, 0), (1, 0, 0)} {
        \draw[dashed, black] (bul) -- + \direction;
    }


    \fill[red!60,   opacity=0.5]  (tll) -- (tul)  -- (bur) -- (blr);
    \fill[blue!60, opacity=0.5]  (bll)   -- (bul)   -- (tur) -- (tlr);




    \draw (bll) -- (blr) -- (tlr) -- (tll) -- cycle;
    \draw (blr) -- (bur) -- (tur) -- (tlr) -- cycle;
    \draw (tll) -- (tlr) -- (tur) -- (tul) -- cycle;

    \foreach \point in {bll, blr, bur, tll, tlr, tul, tur} {
        \fill[fill opacity=1] (\point) circle (0.75pt);
    }


\node[below] at (1.0, -0.2, 0.0) {$AC$};

\end{tikzpicture}
\end{document}

答案1

只需改变z-方向,这样点就不再共线了。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[scale = 4, thick,
    % change the z-direction
    z={(-0.3,-0.6)}]

    %% Define coordinate labels.
    % t(op) and b(ottom) layers
    \path \foreach \layer/\direction in {b/{0, 0, 0}, t/{0, 1, 0}} {
        (\direction)
        \foreach \point/\label in {{0, 0, 0}/ll, {1, 0, 0}/lr, {1, 0, -1}/ur, {0, 0, -1}/ul} {
            +(\point) coordinate (\layer\label)
        }
        ($(\layer ll)!0.5!(\layer ur)$) coordinate (\layer md)
    };

    % Put text next to the labels as requested.
    \draw \foreach \text/\label/\anchor in {%
        $\left(1\right)$/bll/east,
        $b$/bul/east,
        $c$/tll/east,
        $bc$/tul/east,
        $a$/blr/west,
        $ab$/bur/west,
        $ac$/tlr/west,
        $abc$/tur/west} {
        (\label) node[anchor=\anchor] {\text}
    };
    % Draw  cube.
    \fill (0, 0, -1) circle (0.5pt);
    \foreach \direction in {(0, 0, 1), (0, 1, 0), (1, 0, 0)} {
        \draw[dashed, black] (bul) -- + \direction;
    }

    % add some midpoints for correct drawing of transparent planes
    \coordinate (m1) at ($(bll)!0.5!(tlr)$);
    \coordinate (m2) at ($(bul)!0.5!(tur)$);

    \fill[blue!60, opacity=0.5]  (bll)   -- (bul)   -- (m2) -- (m1) -- cycle;
    \fill[red!60,   opacity=0.5]  (tll) -- (tul)  -- (bur) -- (blr) -- cycle;
    \fill[blue!60, opacity=0.5]  (m1) -- (m2) -- (tur) -- (tlr) -- cycle;
    \draw[very thin, black!60] (m1) -- (m2);

    \draw (bll) -- (blr) -- (tlr) -- (tll) -- cycle;
    \draw (blr) -- (bur) -- (tur) -- (tlr) -- cycle;
    \draw (tll) -- (tlr) -- (tur) -- (tul) -- cycle;

    \foreach \point in {bll, blr, bur, tll, tlr, tul, tur} {
        \fill[fill opacity=1] (\point) circle (0.75pt);
    }
\end{tikzpicture}
\end{document}

结果

相关内容