23

5

From an external simulation program, I have lots of particle tracks which follow random walks, all of which start at or near the origin $(0,0)$. This means that when I plot the walks in *Mathematica*, it looks a bit of a mess because all the tracks overlap with each other.

For example:

```
randomwalks = Table[
Accumulate@RandomVariate[StableDistribution[1, 1.7, 0, 0, 2], {512, 2}],
{i, 3}];
ListLinePlot[randomwalks, PlotRange -> Full, PlotTheme -> "Minimal",
Axes -> None, Frame -> True, AspectRatio -> 1];
```

This gives the image on the left - the fact that all the walks start near the origin means that they overlap and it's hard to see what is going on.

What I'd like to plot instead is something like the image on the right, where the random walks have been manually translated to stop them overlapping.

Is there a way to achieve this translation automatically withMathematica?

The direction of each jump in the random walk is important, so I want to keep this in the visualization (hence translations only and no rotations).

Note also the choice of a Lévy-stable distribution for the random walk rather than the normal distribution. This typically gives walks that are more spread-out with longer jumps (due to the fat distribution tails). In turn this leads to a more diverse spread of shapes to try and fit together, and means arranging the shapes in a simple grid (e.g. via `Column[Graphics /@ Line /@ randomwalks]`

is not always as successful as I'd like.

My first thought was to calculate the bounding rectangle for each track, and then use the code in An algorithm to space out overlapping rectangles? to space out those bounding rectangles. However, this might leave large regions of whitespace due to the nature of the random walks, so perhaps a bounding polygon might be better to give a tighter arrangement of the tracks.

Given I have the track data itself, is there perhaps a way to do it without using the bounding rectangles? As suggested in a comment, perhaps using the convex hull of each path and then packing the resulting polygons?

```
regions = ConvexHullMesh[#] &/@ randomwalks
centroids = RegionCentroid[#] &/@ regions
```

Once we have the centroids, one approach would be to minimize the Euclidean distance between each centroid whilst ensuring the regions don't overlap - but that would need a function such as `RegionOverlapQ[]`

or similar.

Maybe it could be done with the help of rasterization and procedures described in 2334 and 88846

– shrx – 2015-09-10T11:23:04.4405One idea: Take the convex hull of each path, and then your problem is reduced to packing convex polygons. – Joseph O'Rourke – 2015-09-10T11:23:59.637

@JosephO'Rourke "convex hull" - that's the term I was looking for! Nice idea. – dr.blochwave – 2015-09-10T11:30:22.867

5Caveat: Optimal packing of convex polygons into a rectangular box is NP-hard, so you will be forced to use heuristics. (Mma has

`ConvexHull[ ]`

.) – Joseph O'Rourke – 2015-09-10T11:34:49.580@JosephO'Rourke sure - it needn't be optimal, just visually pleasing! – dr.blochwave – 2015-09-10T11:39:10.630

2Why not just

`Column[Graphics /@ Line /@ randomwalks]`

or something? – Kuba – 2015-09-10T11:41:49.8032@Kuba because I fancied a challenge? :-) – dr.blochwave – 2015-09-10T11:43:09.887

1why only translations and no rotations? – Nikolay Gromov – 2015-09-10T13:42:04.610

@NikolayGromov because in the output from my simulation program, the direction of each jump is important and I want to keep that in the visualization (good point though, will clarify in the question) – dr.blochwave – 2015-09-10T13:46:23.963

2OMG My code there is mess – Dr. belisarius – 2015-09-10T14:21:56.703

1

One approximative approach to this is related to tiling a region with a set of polynominoes approximating individual random walks. This can be solved, for example, using binary integer linear programming. Time to find instances of these solutions is not necessarily nice. I have a crude solution to this problem, but code is truly awful at this point...

– kirma – 2015-09-10T17:57:13.113