2

This is a a curved cube

\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}

How to fill faces with different colors?

2
  • 1
    We kindly suggest you to show a full minimal working example (MWE) including \documentclass{...} and ending with \end{document}.
    – Cragfelt
    Commented Mar 29, 2019 at 1:24
  • It is possible but cumbersome to fill the faces since their boundaries are intersection segments. I believe it will be much simpler if you redraw the paths in single stretches using to[in=...,out=..] such that successive stretches are smoothly connected.
    – user121799
    Commented Mar 29, 2019 at 1:46

1 Answer 1

5

In general, you can recover parts of a path using pgfplots (!) library fillbetween, and these parts can be used to fill some area they are confining. Your example is special in that you have the coordinates of the vertices explicitly. So you can store the subpaths using show path construction. The following MWE does that in the following way:

  1. If you add record path construction, the subpaths (and their reversed versions) will be stored in a list.
  2. You can redraw the subpaths or combine them to form a boundary of a face.

Unfortunately I find the names of your coordinates not too easy to interpret, but you will find it of course easier. For example,

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

The numbers here depend on the order in which you draw the paths.

\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}

enter image description here

Figuring all the subpaths is possible but may require some patience. If you want, say, to know what segment number 40 is, do

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

enter image description here

The arrow indicates the direction. The path number 41 will run through the same curve but in opposite direction. If you want to get a survey of all segments, uncomment

\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}

enter image description here

Notice that the way to record the paths and label/number them is not unique, there might be better ways.

3
  • ... and marmot did it again!
    – manooooh
    Commented Mar 29, 2019 at 5:09
  • 1
    Excellent! Unfortunately, I do not understand the construction of the "record path construction", but understand how to use it in different situations.
    – nail
    Commented Mar 29, 2019 at 20:14
  • @nail All it does is to store certain subpaths in a list such that you can later recycle them e.g. in order to fill some area enclosed by them. The name of the decoration show path construction may indeed not be optimal, an alternative name would be access to path information.
    – user121799
    Commented Mar 29, 2019 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .