Attempting to draw a random polymer mesh, which I intended to visualize by drawing a series of random walks between (x,0) and (x,1) where x is arbitrary. My first attempt is attached, and it compiles. But if I change certain things it gives the error message "Package tikz Error: Giving up on this path. Did you forget a semicolon? }}" Given this I have not progressed beyond this, my first attempt.
By "certain things" I mean for example removing "nicefrac" or sometimes arbitrarily altering the \foreach statements. Or even if I change the starting coordinates for coordinate A to for example (rand,rnd).
The code below is then clearly not ideal. The lines, if not drawn as ultra thin, have ugly gaps at each joint, there is the error message I do not understand where comes from. So, how can I draw a messy mesh in a better fashion?
The rules are simple: Each polymer chain in the mesh is drawn as a set of jointed segments of equal length. The joints between these should be able to deviate only by a certain angle (Depending on the polymer stiffness) and they should all remain within a given distance of the drawn surface. If they reach this limit, the polymers will bend back down or up, as the case may be.
\documentclass{article}
\usepackage{tikz}
\usepackage{nicefrac}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}%
\begin{document}
\begin{tikzpicture}
\clip (-.5,-.5)rectangle(.5,2);
\foreach \x in {-1.0,-.9,...,1}{
\draw[ultra thin] (\x,0.1) coordinate[name=A];
\foreach \y in {0,.2,...,10}{
\ExtractCoordinate{A}
\ifthenelse{\lengthtest{\YCoord <28 pt}}%Checked if below 1.
{%Is below 1.
\ifthenelse{\lengthtest{\YCoord >0 pt}}{%Check if above 0
\draw[ultra thin] (A)--++(rand*120:.05) coordinate[name=A];%Yes, above zero
}{\draw[ultra thin] (A)--++(rnd*89:.05) coordinate[name=A];}%NOT above zero
}%Is not below 1
{\draw[ultra thin] (A)--++(-rnd*89:.05) coordinate=name=A];
}%ELSE 1
}}
\draw[fill=blue!15] (-1,0)rectangle(1,-1);%surface coated by the mesh
\end{tikzpicture}
\end{document}
The code results in something akin to this:
or this, with normal line thickness:
which is fairly close to what I would like, though I would like to tweak the behavior of the angles somewhat so I can change how far each polymer segment can bend (Thereby simulating different polymer stiffnesses). Also, at this point, all polymers tend to move to the right, their motion is not truly random but directed in one direction.
nicefrac
, you are removing theifthen
package (which is loaded bynicefrac
) so\ifthenelse
is not defined anymore. In fact, you don’t need\ifthenelse
since PGFmath provides that for you. Can you show us how that mesh looks usually? What are the rules?