9

Let's me begin by saying that I am a complete newbie. I have been trying to draw the following image but didn't get very far:

wanted

The following is what I have so far: enter image description here

\documentclass[border=5mm,tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\definecolor{DarkOceanSky}{RGB}{133,163,229}
\definecolor{Reu}{RGB}{102,173,76}
\definecolor{Crimson}{RGB}{220, 20, 60}

\tikzset{% define a pic for the little squares: takes colour and label as arguments
   pics/mysquare/.style args={#1, #2}{
     code={\draw[#1](-0.2,-0.2) rectangle (0.2,0.2);
           \draw[fill=#1] circle[#1,radius=2pt](0,0);
           \node[#1] at (0.4,-0.08){$#2$};
}}}

\begin{document}
    \begin{tikzpicture}

        \begin{scope}[my square/.style={rectangle,draw=red,minimum width=1em, minimum height=1em}]
                \draw[fill=Reu] (0,1)--(1.25,1.6)--(2.95,3)--(2.25,4)--(0,4)--(0,1);
                \draw[fill=DarkOceanBlue](1.25,1.6)--(2.95,3)--(2.25,4)--(4,4)--(4,1.9)--(2.75,2)--cycle;
                \draw[very thick, Crimson,rounded corners] (0,1)--(1.25,1.6)--(2.75,2)--(4, 1.9);
                \draw[thick] (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;
                \node[right] at (1.7, 0.8) (e2) {\fontsize{12}{5} \selectfont $\Omega$};
                \node[right, rotate=22] at (0.2, 0.95) (e2) {\fontsize{8}{5} \selectfont $\delta \Omega$};
                \node[right] at (0.8, 3.3) (e2) {\fontsize{12}{5} \selectfont $\Phi$};
        \end{scope}

        \begin{scope}[my square/.style={rectangle,draw=red,minimum width=1em, minimum height=1em}, xshift=116]
                \draw[fill=Reu] (0,1)--(1.25,1.6)--(2.95,3)--(2.25,4)--(0,4)--(0,1);
                \draw[fill=DarkOceanBlue](1.25,1.6)--(2.95,3)--(2.25,4)--(4,4)--(4,1.9)--(2.75,2)--cycle;
                \draw[very thick, Crimson,rounded corners] (0,1)--(1.25,1.6)--(2.75,2)--(4, 1.9);
                \draw[thick] (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;
                \draw (1.25,1.6) pic{mysquare={Crimson, p}};
                \node[right] at (1.7, 0.8) (e2) {\fontsize{12}{5} \selectfont $\Omega$};
                \node[right, rotate=22] at (0.2, 0.95) (e2) {\fontsize{8}{5} \selectfont $\delta \Omega$};
                \node[right] at (0.8, 3.3) (e2) {\fontsize{12}{5} \selectfont $\Phi$};
        \end{scope}

        \begin{scope}[my square/.style={rectangle,draw=red,minimum width=1em, minimum height=1em}, xshift=232]
                \draw[fill=Reu] (0,1)--(1.25,1.6)--(2.95,3)--(2.25,4)--(0,4)--(0,1);
                \draw[fill=DarkOceanBlue](1.25,1.6)--(2.95,3)--(2.25,4)--(4,4)--(4,1.9)--(2.75,2)--cycle;
                \draw[very thick, Crimson,rounded corners] (0,1)--(1.25,1.6)--(2.75,2)--(4, 1.9);
                \draw[thick] (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;
                \draw (1.25,1.6) pic{mysquare={Crimson, p}};
                \draw (2.735,3.3) pic{mysquare={yellow, q''}};
                \draw ($ (1.25,1.6)!0.5!(2.95,3) $) pic{mysquare={yellow, q'}};
                \node[right] at (1.7, 0.8) (e2) {\fontsize{12}{5} \selectfont $\Omega$};
                \node[right, rotate=22] at (0.2, 0.95) (e2) {\fontsize{8}{5} \selectfont $\delta \Omega$};
                \node[right] at (0.8, 3.3) (e2) {\fontsize{12}{5} \selectfont $\Phi$};
        \end{scope}

        \node[right] at (1.7, -0.3) (e2) {\fontsize{12}{5} \selectfont  a};
        \node[right] at (5.75, -0.3) (e2) {\fontsize{12}{5} \selectfont  b};
        \node[right] at (9.8, -0.3) (e2) {\fontsize{12}{5} \selectfont  c};
    \end{tikzpicture}
\end{document}

Could you show me how to draw the last square (where part of the red line is modified)!

4
  • 2
    BTW: do you really want to have $\delta\Omega$, not $\partial\Omega$? It seems to be a boundary... Commented May 21, 2015 at 1:25
  • 1
    Hi Przemysław, I don't much care about the text. Just the figure would do.
    – wererabit
    Commented May 21, 2015 at 2:00
  • 1
    Check pgf manual and tikz pgf manual in this document you find almost everything you need.
    – Jan-Bert
    Commented May 21, 2015 at 5:33
  • What do these diagrams represent?
    – user30471
    Commented May 21, 2015 at 14:00

1 Answer 1

11

Here is one way to do this. The interesting part is the use of pic to draw your little squares by defining a new "picture" called mysquare. These squares take two arguments: the colour and the label.

Here is the image my code produces.

enter image description here

Here is the code:

\documentclass[border=5mm,tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,decorations}

\tikzset{% define a pic for the little squares: takes colour and label as arguments
   pics/mysquare/.style args={#1,#2}{
     code={\draw[thick,#1](-0.2,-0.2) rectangle (0.2,0.2);
           \draw[fill=#1] circle[#1,radius=2.5pt](0,0);
           \node[black] at (0.4,0){$#2$};
}}}

\begin{document}
\begin{tikzpicture}[my square/.style={rectangle,draw=red,minimum width=1em, minimum height=1em}]
    \draw[fill=green!80!blue] (0,1)--(1.25,1.6)--(2.95,3)--(2.25,4)--(0,4)--(0,1);
    \draw[blue, fill=blue](1.25,1.6)--(2.95,3)--(2.25,4)--(4,4)--(4,1.9)--(2.75,2)--cycle;
    \draw[very thick, red,rounded corners] (0,1)--node[below=-1mm,black,rotate=30]{$\delta\Omega$}(1.25,1.6)--(2.75,2)--(4, 1.9);
    %\draw[thick, fill=green] (0,1) -- (4,0) -- (4,4) -- (0,4) -- cycle;
    \draw[very thick] (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;
    \draw (1.25,1.6) pic{mysquare={yellow, p}};
    \draw ($ (1.25,1.6)!0.6!(2.95,3) $) pic{mysquare={red, q'}};
    \draw ($ (2.25,4)!0.5!(2.95,3) $) pic{mysquare={red, q''}};
    \node at (3,1){$\Omega$};
    \node at (2,3){$\Phi$};
\end{tikzpicture}
\end{document}

Apart from the mysquare pic the other interesting line of the code is the coordinate:

 ($ (1.25,1.6)!0.6!(2.95,3) $)

This is done with the tikz calc library and it computes the point that is 60% of the way along the line joining the two points (1.25,1.6) and (2.95,3). Similarly, (1.25,1.6)!0.2!2.95,3) would pick the point one fifth of the way along this line. The ($ ... $) tells tikz to enter "calculation mode".

Edit As requested, here is the code for your last diagram. I have dropped the rounded edges as this is easier. Note also that the second \draw command should be

\draw[blue, fill=blue]...

In particular, the blue will get rid of the black line that you have in your diagrams separating the green and blue regions.

enter image description here

\documentclass[border=5mm,tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,decorations}

\tikzset{% define a pic for the little squares: takes colour and label as arguments
   pics/mysquare/.style args={#1, #2}{
     code={\draw[thick,#1](-0.2,-0.2) rectangle (0.2,0.2);
           \draw[fill=#1] circle[#1,radius=2.5pt](0,0);
           \node[black] at (0.4,0){$#2$};
}}}

\begin{document}
\begin{tikzpicture}[my square/.style={rectangle,draw=red,minimum width=1em, minimum height=1em}]
    \draw[fill=green!80!blue] (0,1)--(1.25,1.6)--++(0,-0.2)--(2.95,3)--(2.25,4)--(0,4)--(0,1);
    \draw[blue, fill=blue](1.25,1.4)--++(0.3,0)--++(0,0.2)--(2.75,2)--(4,1.9)--(4,4)--(2.25,4)--(2.95,3)--cycle;
    \draw[very thick, red] (0,1)--node[below=-0.5mm,black,rotate=25]{$\delta\Omega$}(1.25,1.6)--++(0,-0.2)--++(0.3,0)--++(0,0.2)--(2.75,2)--(4, 1.9);
    %\draw[thick, fill=green] (0,1) -- (4,0) -- (4,4) -- (0,4) -- cycle;
    \draw[very thick] (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;
    %\draw (1.25,1.6) pic{mysquare={yellow, p}};
    \draw ($ (1.25,1.6)!0.6!(2.95,3) $) pic{mysquare={red, q'}};
    \draw ($ (2.25,4)!0.5!(2.95,3) $) pic{mysquare={red, q''}};
    \node at (3,1){$\Omega$};
    \node at (2,3){$\Phi$};
\end{tikzpicture}
\end{document}
1
  • Thanks, I manage to use your code to create the first three square. Could you show me how to draw the last square?
    – wererabit
    Commented May 21, 2015 at 22:00

You must log in to answer this question.

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