I want to draw the physical model of graph that has a ball for each vertex and a piece of string for each edge. In this model, if you lift a ball high enough, the other balls are pulled up along with it, affected by both the stress of strings and gravity. An illustration is shown in the following figure.
However, using tikz-qtree
, I can only draw an ordinary tree which cannot visualize the strings or gravity (and is somewhat ugly).
Therefore, I want to know that
How to draw the physical tree with balls under both the stress of strings and gravity?
My code using tikz-qtree
is as follows.
\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\node [draw, circle] (r) at (0,0) {$r$};
\node [draw, circle, blue, very thick] (s) at (2,0) {$s$};
\node [draw, circle] (t) at (4,0) {$t$};
\node [draw, circle] (u) at (6,0) {$u$};
\node [draw, circle] (v) at (0,-2) {$v$};
\node [draw, circle] (w) at (2,-2) {$w$};
\node [draw, circle] (x) at (4,-2) {$x$};
\node [draw, circle] (y) at (6,-2) {$y$};
\draw (r) to (v);
\draw (r) to (s);
\draw (s) to (w);
\draw (t) to (u);
\draw (t) to (w);
\draw (t) to (x);
\draw (u) to (x);
\draw (u) to (y);
\draw (x) to (y);
\draw (y) to (u);
\end{tikzpicture}
\begin{tikzpicture}[]
\tikzset{level distance = 36pt, sibling distance = 25pt}
\tikzset{every node/.style = {draw, circle}}
\Tree [.\node[blue, very thick](s){$s$};
[.$r$ $v$ ]
[.\node(w){$w$};
[.\node(t){$t$}; \node(u){$u$}; ]
[.\node(x){$x$}; \node(y){$y$}; ]
]
]
% cross edges
\draw [dashed, thick, red] (t) to [out = -45, in = 225] (x);
\draw [dashed, thick, red] (u) to [out = -45, in = 225] (y);
\draw [dotted, thick, purple] (x.-110) to (u);
\end{tikzpicture}
\end{document}
tkz-graph
package. Documentation in French, but with lots of examples to play with. It doesn't do exactly what you want, but it is designed for graphs and not trees; anything you do withtikz-qtree
will likely be very hacky, since it's not designed for that. See also Multi-rooted Tree-like Structures and Nodes with Multiple Parents in LaTeX. – Alan Munn Nov 18 '14 at 6:30