A brilliant aspect of the Wolfram Language is that not only you can do virtually anything with it, you can also do whatever you want in many different ways. You can choose the method you prefer, or even better, try several methods to understand your problem from different perspectives.

For example, when drawing a graphic, we usually specify the coordinates of its points or elements. But sometimes it’s simpler to express the graphic as a collection of relative displacements: move a distance *r* in a direction forming an angle *θ* with respect to the direction of the segment constructed in the previous step. This is known as turtle graphics in computer graphics, and is basically what the new function `AnglePath` does. If all steps have the same length, use `AnglePath`[{*θ*1,*θ*2,...}] to specify the angles. If each step has a different length, use `AnglePath`[{{r1,*θ*1},{r2,*θ*2}, ...}] to give the pairs {length, angle}. That’s it. Let’s see some results.

Turn 60 degrees to the left with respect to the previous direction six times. You get a hexagon:

If the angle is 135 degrees and you repeat eight times, then this is the result. Note that 8 * 135° = 1080°, so we go around the center three times:

Suppose that we again keep turning the same positive angle *θ*, but we increase the lengths of the steps linearly, in increments *dr*, from 0 to 1:

Then we get these curves that spiral outward, producing nice outputs:

If we choose the angles randomly, we get random walks on the plane:

Now let’s try to combine multiple `AnglePath` lines. Suppose that at each step we choose randomly between two possible angles and that the lengths obey a power law, so they get smaller in each iteration:

The result does not look very interesting yet:

But if we repeat the experiment 10 times, then we start seeing some structure:

We can construct all different lists of 10 choices of the two angles, using `Tuples` (there are 2^10=1024 possible lists). Replacing `Line` with `BSplineCurve` produces curved lines instead of straight segments. The result is a nice self-similar structure:

`AnglePath` allows us to construct fractal structures easily, with very compact code. In fact, the code fits in a tweet! These are two examples derive from Wolfram Tweet-a-Program:

These curious spirals are approximate Cornu spirals. With larger steps, they develop interesting substructure:

This was a quick introduction to how useful and fun the function `AnglePath` can be. `AnglePath` is supported in Version 10.1 of the Wolfram Language and *Mathematica*, and is rolling out soon in all other Wolfram products. Start using it now, and tweet your results through Wolfram TaP!

Download this post as a Computable Document Format (CDF) file.

## 4 Comments

One longtime personal interest of mine is the Collatz conjecture. This Manipulate takes the Collatz function from ExampleData and allows you to adjust the angle and number to evaluate. It then produces an AnglePath Graphics object from the sequence produced by evaluating the Collatz rule with the number:

<< ExampleData/Collatz.m;

Manipulate[

Graphics[Line[

AnglePath[Table[{r, a \[Degree]}, {r, Collatz[n]}]]]], {a, 0,

360}, {n, 1, 100, 1}]

You can get some interesting patterns, and it's actually quite a nice visualization of the Collatz sequence. At first glance it might appear to be a random walk-like structure, but upon further examination areas of repetition appear.

I like this! Try this one:

Manipulate[seed;

Graphics[{ColorData["DeepSeaColors"][RandomReal[]],

Thickness[0.0005 + 0.01 ((max - #)/max)^(4 e)],

Opacity[0.05 + 0.5 (#/max)^3],

Line[AnglePath[

Table[{r/(1 + r^e), a Pi (0.7 - 2 Mod[r, 2]) }, {r,

Reverse@Collatz[#]}]]]} & /@

Reverse[Sort@RandomSample[Range[max], n]]], {{e, 1.2}, 0.01,

3}, {{a, 0.08}, 0, 1}, {{n, 800}, 1, 2000, 1}, {{max, 200000000}, n,

200000000}, {seed, 0, 1}, TrackedSymbols :> {n, max, seed, e, a}]

The Wolfram Language is just an amazing tool. Every day, I’m amazed of what I can do with this tool! Keep the great work!

I do hope that they will also add a 3D analogon, where you specify, besides turn angle and travel distance, also the roll angle of the 3D turtle.

See for instance the following demonstration: http://demonstrations.wolfram.com/3DFlyingPipeLayingTurtle/

3D turtle geometry is much more interesting/challenging than the 3D variant. See

Tom Verhoeff.

“3D Turtle Geometry: Artwork, Theory, Program Equivalence and Symmetry”.

Int. J. of Arts and Technology, 3(2/3):288-319 (2010).