4

I have a network described by two graph layers, where in both layers I have to draw a different graph. Each level describes a different abstraction level, where one could be expanded into more components, as in the following code, where Firms contains Firma1 and Firma2.

% Interaction diagram
% Author: Pascal Seppecher
% Based on diagram from Marco Miani.
\documentclass{article}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{fit,shapes}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{comment}
:Title: Interaction diagram
:Tags: Scopes,3D, Diagrams,Transparency,Economics,Computer Science
:Author: Pascal Seppecher
:Slug: interaction-diagram

Real and monetary flows in an agent-based 
macroeconomic model with endogenous money.
\end{comment}
\usetikzlibrary{positioning}
\newcommand{\MonetaryLevel}{Monetary level}
\newcommand{\RealLevel}{Real level}
\newcommand{\Firms}{Firms}
\newcommand{\Households}{Households}
\newcommand{\Banks}{Banks}
\newcommand{\Commodities}{Commodities}
\newcommand{\LaborPower}{Labor power}
\newcommand{\Wages}{Wages}
\newcommand{\Consumption}{Consumption}
\newcommand{\Credits}{Credits}
\newcommand{\Withdrawals}{Withdrawals}
\newcommand{\Deposits}{Deposits}
\newcommand{\Repayments}{Repayments}

\newcommand{\yslant}{0.5}
\newcommand{\xslant}{-0.6}
\begin{document}
\begin{tikzpicture}[scale=1.1,every node/.style={minimum size=.1cm},on grid]

    % Real level
    \begin{scope}[
        yshift=-120,
        every node/.append style={yslant=\yslant,xslant=\xslant},
        yslant=\yslant,xslant=\xslant
    ] 
        % The frame:
        \draw[black, dashed, thin] (0,0) rectangle (7,7); 
        % Agents:
        \node[fill=red,draw=black,label=above:\textbf{firma1}] at (3,3) (a) {};
        \node[fill=red,draw=black,label=above:\textbf{firma2}] at (5,3) (b) {};
        \node[ellipse,fit=(a) (b), fill=red,draw=black, opacity=0.5] (c) {};
    \end{scope}

    % 2 vertical lines for linking agents on the 2 levels
    \draw[ultra thin](3.8,4) to (c.west);
    \draw[ultra thin](3.8,4) to (c.east);

    % Monetary level
    \begin{scope}[
        yshift=0,
        every node/.append style={yslant=\yslant,xslant=\xslant},
        yslant=\yslant,xslant=\xslant
    ]
        % The frame:
        \fill[white,fill opacity=.75] (0,0) rectangle (7,7); % Opacity
        \draw[black, dashed, thin] (0,0) rectangle (7,7); 
         % Agents:
        \draw [fill=red]
            (5,2) circle (.1) % Firms
            (2,2) circle (.1) % Households
            (3.5,5) circle (.1); % Banks
         % Monetary Flows:
        \draw[-latex, thin]
            (3.65,5.1) to[out=30,in=30] (5.15,2.1); % Credits
        \draw[-latex, thin]
            (5,1.8) to[out=-90,in=-90] (2,1.8); % Wages
        \draw[-latex, thin]
            (1.9,2.1) to[out=150,in=150] (3.4,5.1);  % Deposits
        \draw[-latex, thin]
            (3.6,4.9) to[out=-30,in=-30] (2.1,1.9); % Withdrawals
        \draw[-latex, thin]
            (2,2.2) to[out=90,in=90] (5,2.2); % Consumption
        \draw[-latex, thin]
            (4.85,1.9) to[out=210,in=210] (3.35,4.9) ; % Repayments
         % Labels:
        \fill[black]
            (0.5,6.5) node[right, scale=.7] {\MonetaryLevel}
            (5.1,1.9) node[right,scale=.7]{\textbf {\Firms}}
            (1.9,1.9) node[left,scale=.7]{\textbf {\Households}}
            (3.5,5.1) node[above,scale=.7]{\textbf {\Banks}}
            (5.5,2.8) node [above, scale=.6, rotate=-100] {\Credits}
            (2.6,1.3) node [above, scale=.6, rotate=-10] {\Withdrawals}
            (2.9,4.25) node [above, scale=.6, rotate=50] {\Repayments}
            (2.6,5) node [above, scale=.6, rotate=25] {\Deposits}
            (4.7,2.9) node [above, scale=.6, rotate=-60] {\Consumption}
            (2.3,1.3) node [below, scale=.6, rotate=-40] {\Wages}; 
    \end{scope} 
\end{tikzpicture}
\end{document}

enter image description here

The two nodes, Firma1 (node a) and Firma2 (node b), are contained inside another node (node c). In order to remark the containment relation, I would like to draw a truncated cone delimited by node c and Firms. Is there a way to do it without defining the explicit coordinates between the two and giving a tridimensional aspect to it? Thanks in advance.

2

The calc library offers the tangent coordinate system:

\node[circle, draw] (a);
\coordinate (b) at (5,5);
\draw (b) -- (tangent cs:node=a,point={(b)},solution=1);

Draws a line from (b) to its respective tangent point in the circle delimited by the circle around (a). We can use this in your drawing, but we need to have all nodes previously defined so we have to make the Firms circle as a node, no problem there. Then, after the all the necessary nodes have been defined we can call:

\draw[ultra thin](c.east) to (tangent cs:node=firms,point={(c.east)},solution=1);
\draw[ultra thin](c.west) to (tangent cs:node=firms,point={(c.west)},solution=2);

You could wonder if it's not possible to calculate the tangent points for both circles, and it is. But, the node (c) is no circle, then we get the error I do not know how to calculate the tangent point for an ellipse. Also since the drawing is at the end its done on the front layer and the line is not on the back of the Real level.

We mustn't worry, the backgrounds library is our friend. Also, if you compile with the previous solution you'll see that the (c.west) and east are not actual tangent points so we have to manually fix that, fortunately I got it right on the second guess:

\scoped[on background layer]{
  \draw[ultra thin](c.-10) to (tangent cs:node=firms,point={(c.-10)},solution=1);
  \draw[ultra thin](c.150) to (tangent cs:node=firms,point={(c.150)},solution=2);
};

MWE:

(notes: must add the calc and background libraries in your original code, as well as make the red Firms circle as a node and have node c with outer sep=0pt)

% Interaction diagram
% Author: Pascal Seppecher
% Based on diagram from Marco Miani.
\documentclass{standalone}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{fit,shapes,calc,backgrounds}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{comment}
:Title: Interaction diagram
:Tags: Scopes,3D, Diagrams,Transparency,Economics,Computer Science
:Author: Pascal Seppecher
:Slug: interaction-diagram

Real and monetary flows in an agent-based 
macroeconomic model with endogenous money.
\end{comment}
\usetikzlibrary{positioning}
\newcommand{\MonetaryLevel}{Monetary level}
\newcommand{\RealLevel}{Real level}
\newcommand{\Firms}{Firms}
\newcommand{\Households}{Households}
\newcommand{\Banks}{Banks}
\newcommand{\Commodities}{Commodities}
\newcommand{\LaborPower}{Labor power}
\newcommand{\Wages}{Wages}
\newcommand{\Consumption}{Consumption}
\newcommand{\Credits}{Credits}
\newcommand{\Withdrawals}{Withdrawals}
\newcommand{\Deposits}{Deposits}
\newcommand{\Repayments}{Repayments}

\newcommand{\yslant}{0.5}
\newcommand{\xslant}{-0.6}
\begin{document}
\begin{tikzpicture}[scale=1.1,every node/.style={minimum size=.1cm},on grid]

    % Real level
    \begin{scope}[
        yshift=-120,
        every node/.append style={yslant=\yslant,xslant=\xslant},
        yslant=\yslant,xslant=\xslant
    ] 
        % The frame:
        \draw[black, dashed, thin] (0,0) rectangle (7,7); 
        % Agents:
        \node[fill=red,draw=black,label=above:\textbf{firma1}] at (3,3) (a) {};
        \node[fill=red,draw=black,label=above:\textbf{firma2}] at (5,3) (b) {};
        \node[ellipse,fit=(a) (b), fill=red,draw=black, opacity=0.5,outer sep=0] (c) {};
    \end{scope}

    % Monetary level
    \begin{scope}[
        yshift=0,
        every node/.append style={yslant=\yslant,xslant=\xslant},
        yslant=\yslant,xslant=\xslant
    ]
        % The frame:
        \fill[white,fill opacity=.75] (0,0) rectangle (7,7); % Opacity
        \draw[black, dashed, thin] (0,0) rectangle (7,7); 
         % Agents:
        \draw [fill=red]
            (5,2) node[circle, inner sep=0pt, minimum size=.2cm, draw, fill, name=firms,node contents={}] % Firms
            (2,2) circle (.1) % Households
            (3.5,5) circle (.1); % Banks
         % Monetary Flows:
        \draw[-latex, thin]
            (3.65,5.1) to[out=30,in=30] (5.15,2.1); % Credits
        \draw[-latex, thin]
            (5,1.8) to[out=-90,in=-90] (2,1.8); % Wages
        \draw[-latex, thin]
            (1.9,2.1) to[out=150,in=150] (3.4,5.1);  % Deposits
        \draw[-latex, thin]
            (3.6,4.9) to[out=-30,in=-30] (2.1,1.9); % Withdrawals
        \draw[-latex, thin]
            (2,2.2) to[out=90,in=90] (5,2.2); % Consumption
        \draw[-latex, thin]
            (4.85,1.9) to[out=210,in=210] (3.35,4.9) ; % Repayments
         % Labels:
        \fill[black]
            (0.5,6.5) node[right, scale=.7] {\MonetaryLevel}
            (5.1,1.9) node[right,scale=.7]{\textbf {\Firms}}
            (1.9,1.9) node[left,scale=.7]{\textbf {\Households}}
            (3.5,5.1) node[above,scale=.7]{\textbf {\Banks}}
            (5.5,2.8) node [above, scale=.6, rotate=-100] {\Credits}
            (2.6,1.3) node [above, scale=.6, rotate=-10] {\Withdrawals}
            (2.9,4.25) node [above, scale=.6, rotate=50] {\Repayments}
            (2.6,5) node [above, scale=.6, rotate=25] {\Deposits}
            (4.7,2.9) node [above, scale=.6, rotate=-60] {\Consumption}
            (2.3,1.3) node [below, scale=.6, rotate=-40] {\Wages}; 
    \end{scope}

    % 2 vertical lines for linking agents on the 2 levels
    \scoped[on background layer]{
    \draw[ultra thin](c.-10) to (tangent cs:node=firms,point={(c.-10)},solution=1);
    \draw[ultra thin](c.150) to (tangent cs:node=firms,point={(c.150)},solution=2);
    };
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.