彩色曲面立方体

彩色曲面立方体

这是一个弯曲的立方体

\begin{tikzpicture}[thick,scale=3]
\coordinate (A1) at (0, 0);
\coordinate (A2) at (0, 1);
\coordinate (A3) at (1, 1);
\coordinate (A4) at (1, 0);
\coordinate (B1) at (0.3, 0.3);
\coordinate (B2) at (0.3, 1.3);
\coordinate (B3) at (1.3, 1.3);
\coordinate (B4) at (1.3, 0.3);
\coordinate (C1) at (0.4, 2);
\coordinate (C2) at (2, -0.4);
\coordinate (C3) at (1, .6);
\coordinate (C4) at (2, 0.7);
\coordinate (C5) at (1, 1.6);
\coordinate (C6) at (2, 0.6);
\coordinate (C7) at (2, 0.1);
\coordinate (C8) at (2, 1.6);
\coordinate (C9) at (2, 1.1);
\coordinate (C10) at (.8, 2.2);
\coordinate (C11) at (1.3, 2);
\coordinate (C12) at (1.6, 2);
\draw[draw=black, line width=.5mm] plot [smooth, tension=1] coordinates {(A1) (A2) (C1)};
\draw[draw=black, line width=.5mm] plot [smooth, tension=1] coordinates {(A1) (A4) (C2)};
\draw[draw=black, line width=.5mm] plot [smooth, tension=1] coordinates {(A1) (B1) (C3)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(A2) (A3) (C4)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(A2) (B2) (C5)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(A4) (B4) (C6)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(B1) (B4) (C7)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(A3) (B3) (C8)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(B2) (B3) (C9)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(B1) (B2) (C10)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(A4) (A3) (C11)};
\draw[draw=black] plot [smooth, tension=1] coordinates {(B4) (B3) (C12)};
\draw[fill=blue] (0,0) circle [radius=.02cm];
\draw[fill=blue] (0,1) circle [radius=.02cm];
\draw[fill=blue] (1,0) circle [radius=.02cm];
\draw[fill=blue] (.3,.3) circle [radius=.02cm];
\draw[fill=blue] (1.3,.3) circle [radius=.02cm];
\draw[fill=blue] (.3,1.3) circle [radius=.02cm];
\draw[fill=blue] (1,1) circle [radius=.02cm];
\draw[fill=blue] (1.3,1.3) circle [radius=.02cm];
\node[black] at (-.2,0) {$M_0$};
\node[black] at (1,-.2) {$M_1$};
\node[black] at (.15,.35) {$M_2$};
\node[black] at (-.2,1) {$M_3$};
\node[black] at (1.4,.5) {$M_{12}$};
\node[black] at (.6,1.6) {$M_{32}$};
\node[black] at (.85,1.1) {$M_{31}$};
\node[black] at (1.45,1.5) {$N$};
\node[black] at (1.45,-.3) {$q_1$-linha};
\node[black] at (.7,.6) {$q_2$-linha};
\node[black] at (0,2) {$q_3$-linha};
\end{tikzpicture}

如何用不同的颜色填充面?

答案1

通常,您可以使用 pgfplots (!) 库恢复路径的各个部分fillbetween,并且这些部分可用于填充它们所限制的某些区域。您的示例很特别,因为您明确地拥有顶点的坐标。因此,您可以使用存储子路径show path construction。以下 MWE 按以下方式执行此操作:

  1. 如果添加record path construction,子路径(及其反转版本)将存储在列表中。
  2. 您可以重新绘制子路径或将它们组合起来以形成面的边界。

不幸的是,我发现你的坐标名称不太容易解释,但你当然会发现它更容易。例如,

 \fill[red,opacity=0.3,scale=1/3,redraw segments={1,4,40,13}] ;

这里的数字取决于您绘制路径的顺序。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathreplacing,backgrounds}
\newcounter{segments}
\tikzset{record path construction/.style={decoration={show path construction,
 curveto code={\stepcounter{segments}\stepcounter{segments}
 \ifdefined\LstSegments
 \xdef\LstSegments{\LstSegments,
 "(\tikzinputsegmentfirst) .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..(\tikzinputsegmentlast)","(\tikzinputsegmentlast) .. controls
        (\tikzinputsegmentsupportb) and (\tikzinputsegmentsupporta)
        ..(\tikzinputsegmentfirst)"}
 \else
 \xdef\LstSegments{"(\tikzinputsegmentfirst) .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..(\tikzinputsegmentlast)","(\tikzinputsegmentlast) .. controls
        (\tikzinputsegmentsupportb) and (\tikzinputsegmentsupporta)
        ..(\tikzinputsegmentfirst)"}
 \fi        
    }},postaction=decorate},
 reconstruct segment/.style={/utils/exec=\pgfmathsetmacro{\mysegment}{{\LstSegments}[#1]},
 insert path=\mysegment},
 redraw segments/.style={/utils/exec={\foreach \Segment [count=\nSeg] in {#1}
 {\pgfmathsetmacro{\mysegment}{{\LstSegments}[\Segment]}
 \ifnum\nSeg=1
 \xdef\mysegments{\mysegment}
 \else
 \xdef\mysegments{\mysegments -- \mysegment}
 \fi}},
 insert path=\mysegments},% 
 }
\begin{document}
\begin{tikzpicture}[thick,scale=3]
\coordinate (A1) at (0, 0);
\coordinate (A2) at (0, 1);
\coordinate (A3) at (1, 1);
\coordinate (A4) at (1, 0);
\coordinate (B1) at (0.3, 0.3);
\coordinate (B2) at (0.3, 1.3);
\coordinate (B3) at (1.3, 1.3);
\coordinate (B4) at (1.3, 0.3);
\coordinate (C1) at (0.4, 2);
\coordinate (C2) at (2, -0.4);
\coordinate (C3) at (1, .6);
\coordinate (C4) at (2, 0.7);
\coordinate (C5) at (1, 1.6);
\coordinate (C6) at (2, 0.6);
\coordinate (C7) at (2, 0.1);
\coordinate (C8) at (2, 1.6);
\coordinate (C9) at (2, 1.1);
\coordinate (C10) at (.8, 2.2);
\coordinate (C11) at (1.3, 2);
\coordinate (C12) at (1.6, 2);
\draw[draw=black, line width=.5mm,record path construction] plot [smooth, tension=1] coordinates {(A1) (A2) (C1)};
\draw[draw=black, line width=.5mm,record path construction] plot [smooth, tension=1] coordinates {(A1) (A4) (C2)};
\draw[draw=black, line width=.5mm,record path construction] plot [smooth, tension=1] coordinates {(A1) (B1) (C3)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(A2) (A3) (C4)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(A2) (B2) (C5)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(A4) (B4) (C6)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(B1) (B4) (C7)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(A3) (B3) (C8)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(B2) (B3) (C9)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(B1) (B2) (C10)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(A4) (A3) (C11)};
\draw[draw=black,record path construction] plot [smooth, tension=1] coordinates {(B4) (B3) (C12)};
\begin{scope}[on background layer]
 \fill[red,opacity=0.3,scale=1/3,redraw segments={8,36,17,1}];
 \fill[green!70!black,opacity=0.3,scale=1/3,redraw segments={12,28,33,16}];
 \fill[cyan,opacity=0.3,scale=1/3,redraw segments={44,33,37,24}];
 \fill[orange,opacity=0.3,scale=1/3,redraw segments={20,44,29,41}]; 
 \fill[blue,opacity=0.3,scale=1/3,redraw segments={1,4,40,13}];
\end{scope}
% test a single segment with direction
% \draw[red,thick,scale=1/3,reconstruct segment/.list={40},-latex];
% get all segments with orientation
%\pgfmathruncatemacro{\Ymax}{\value{segments}-1}
% \foreach \X [count=\Y starting from 0] in {1,...,\value{segments}}
% {\ifodd\Y
% \else
% \draw[red,thick,scale=1/3,reconstruct segment/.list={\Y},-latex]
% node[midway,fill=white]{\Y};
% \fi}
\draw[fill=blue] (0,0) circle [radius=.02cm];
\draw[fill=blue] (0,1) circle [radius=.02cm];
\draw[fill=blue] (1,0) circle [radius=.02cm];
\draw[fill=blue] (.3,.3) circle [radius=.02cm];
\draw[fill=blue] (1.3,.3) circle [radius=.02cm];
\draw[fill=blue] (.3,1.3) circle [radius=.02cm];
\draw[fill=blue] (1,1) circle [radius=.02cm];
\draw[fill=blue] (1.3,1.3) circle [radius=.02cm];
\node[black] at (-.2,0) {$M_0$};
\node[black] at (1,-.2) {$M_1$};
\node[black] at (.15,.35) {$M_2$};
\node[black] at (-.2,1) {$M_3$};
\node[black] at (1.4,.5) {$M_{12}$};
\node[black] at (.6,1.6) {$M_{32}$};
\node[black] at (.85,1.1) {$M_{31}$};
\node[black] at (1.45,1.5) {$N$};
\node[black] at (1.45,-.3) {$q_1$-linha};
\node[black] at (.7,.6) {$q_2$-linha};
\node[black] at (0,2) {$q_3$-linha};
\end{tikzpicture}
\end{document}

在此处输入图片描述

找出所有子路径是可能的,但可能需要一些耐心。例如,如果您想知道第 40 段是什么,请执行以下操作

\draw[red,thick,scale=1/3,reconstruct segment/.list={40},-latex];

在此处输入图片描述

箭头指示方向。路径编号 41 将通过相同的曲线,但方向相反。如果您想获取所有路段的调查,请取消注释

\foreach \X [count=\Y starting from 0] in {1,...,\value{segments}}
{\ifodd\Y
\else
\draw[red,thick,scale=1/3,reconstruct segment/.list={\Y},-latex]
node[midway,fill=white]{\Y};
\fi}

在此处输入图片描述

请注意,记录路径和标记/编号的方式并不是唯一的,可能有更好的方法。

相关内容