4

I am using currently tikz to describe a law used in a Theory. This method describes the construction of sub-Area by breaking point in different lines.

I want to reproduce this picture: Area law in PBGRT

In this one, P1, P2 and P2 are the breaking point created randomly in the Line L1, L2 and L3, respectively.

This is the difficult point for me. I have currently done this part :

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}
\draw (0,0) --++ (3,-3) --++ (3.5,3.5) --++ (-3,3) --cycle;
\draw (0.5,1.5) to[dashed] (1,1) -- (4,-2) to[dashed] (4.5,-2.5)node[below right]{$L_1$} ;
\draw (1.5,2.5) to[dashed] (2,2) -- (5,-1) to[dashed] (5.5,-1.5)node[below right]{$L_2$} ;
\draw (2.5,3.5) to[dashed] (3,3) -- (6,0) to[dashed] (6.5,-0.5)node[below right]{$L_3$} ;
\end{tikzpicture}
\end{center}
\end{figure}

But I don't know exactly how to create the Pn points using random variable. Of course, I think about the interpolation expression of Ln lines and place the breaking point Pn in this line but I don't know how.

The second little problem is about the dashed line, I don't know currently how plotted a line dashed in first time then fulled then dashed.

All line + statement of Area etc is dependent of the random placement of Pn. Can you help me to create this picture please?

Thanks

1 Answer 1

5

I managed to draw the entire picture and afterwards rotating it with -45 degrees. This way you can use a random() as your x coordinate:

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

\begin{document}
    \begin{tikzpicture}[line width = .8pt]
        \begin{scope}[rotate=-45]
            \draw (0,0) rectangle (-4,5.5);
            \coordinate (L1) at (0,1.5);
            \coordinate (L2) at (0,3);
            \coordinate (L3) at (0,4.5);
            \coordinate (L4) at (0,6);

            \coordinate (p0) at (-4,0);
            \pgfmathparse{4 * random()}
            \coordinate (p1) at (L1-|-\pgfmathresult,0);
            \pgfmathparse{\pgfmathresult * (1-random())}
            \coordinate (p2) at (L2-|-\pgfmathresult,0);
            \pgfmathparse{\pgfmathresult * (1-random())}
            \coordinate (p3) at (L3-|-\pgfmathresult,0);
            \pgfmathparse{\pgfmathresult * (1-random())}
            \coordinate (p4) at (L4-|-\pgfmathresult,0);

            \foreach \i [remember=\i as \j (initially 0)] in {1,2,3,4}{
                \draw (p\j) -- (p\j|-p\i) edge[dashed] ++ (180:0.75) -- (p\i);
                \draw (p\i) -- (L\i);
                \draw[dashed] (L\i) -- ++(0:0.75) node[pos=1.5]{\( L\i \)};
                \path (p\j) -- (L\i) node[midway]{\( A_\i \)};
                \draw (p\i) circle (0.5mm) node[above=1mm]{\( P_\i \)};
            }

            \draw (p4) -| (0,5.5);

            \draw[<->] (p1) -- node[auto]{\( x \)} (p1|-0,0);
            \draw[<->] ([yshift=-2.5mm]p1) -- node[auto,swap]{\( y \)} ([yshift=-2.5mm]p1-|0,0);
        \end{scope}
    \end{tikzpicture}
\end{document}

It results in (you might need some compilations to get a good result with the random() function):
enter image description here

Small update:
This way one can use a certain part of the previous line without having to wait for random() creating a good value. Also I removed line L4 since that was not drawn in your example image.

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

\begin{document}
    \begin{tikzpicture}[line width = .8pt]
        \begin{scope}[rotate=-45]
            \draw (0,0) rectangle (-4,5.5);
            \coordinate (L1) at (0,1.5);
            \coordinate (L2) at (0,3);
            \coordinate (L3) at (0,4.5);
            \coordinate (L4) at (0,6);

            \coordinate (p0) at (-4,0);
%            \pgfmathparse{4 * random()}
            \pgfmathparse{4 * 0.6}
            \coordinate (p1) at (L1-|-\pgfmathresult,0);
%            \pgfmathparse{\pgfmathresult * (1-random())}
            \pgfmathparse{\pgfmathresult * 0.5}
            \coordinate (p2) at (L2-|-\pgfmathresult,0);
%            \pgfmathparse{\pgfmathresult * (1-random())}
            \pgfmathparse{\pgfmathresult * 0.4}
            \coordinate (p3) at (L3-|-\pgfmathresult,0);
%            \pgfmathparse{\pgfmathresult * (1-random())}
            \pgfmathparse{\pgfmathresult * 0.75}
            \coordinate (p4) at (L4-|-\pgfmathresult,0);

            \foreach \i [remember=\i as \j (initially 0)] in {1,2,3,4}{
                \draw (p\j) -- (p\j|-p\i) edge[dashed] ++ (180:0.75) -- (p\i);
                \path (p\j) -- (L\i) node[midway]{\( A_\i \)};
                \draw (p\i) circle (0.5mm) node[above=1mm]{\( P_\i \)};
            }
            \foreach \i in {1,2,3}{
                \draw (p\i) -- (L\i);
                \draw[dashed] (L\i) -- ++(0:0.75) node[pos=1.5]{\( L\i \)};
            }

            \draw[dashed] (p4) -| (0,5.5);

            \draw[<->] (p1) -- node[auto]{\( x \)} (p1|-0,0);
            \draw[<->] ([yshift=-2.5mm]p1) -- node[auto,swap]{\( y \)} ([yshift=-2.5mm]p1-|0,0);
        \end{scope}
    \end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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