DEV Community

Andrii Yakovenko
Andrii Yakovenko

Posted on

Polar coordinates based on Collattz numbers and 2^n zones revealing droplet pattern

Hello everyone!

So I have been experimenting with a Collatz graph visualization that maps reverse tree in a particular polar coordinate system.

This mapping forces numbers to fall into strict zones which leads to emergence of quite cool geometric patterns (like droplet spirograph)

Below is a brief explanation of the process.

The radial distance is determined by the "zones" to which the number belongs. Zone n is determined by floor(log2(v)) where n represents the [2^n, 2^(n+1)) range. All zones are mapped as circles separated by a particular "ringSpacing"

The angular position is a straightforward linear mapping of a number's position within its particular zone

  • 2^n is fixed at -π/2

  • 2^(n+1)-1 comes close to completing the full circle.

The position of the number itself is proportional to its value within the circle: (number - 2n) / 2n of a whole circle. What is interesting about such mapping is the automatic emergence of fixed structural axes from certain types of numbers. Values of 2n play the role of a major vertical axis, while the centers of these values 3 * 2^(n-1), and sub-centers 5 * 2^(n-2) and 7 * 2^(n-2) play the role of secondary axes and align themselves exactly with points of 1/2, 1/4, and 3/4 on the circumference.

The graph itself is generated in a bottom-up manner through an inverse BFS starting from certain seeds in the reverse Collatz tree. Given any particular number m, we can generate its predecessors as follows:

const inversePredecessors = (
  m: number,
  q: number = 3,
  w: number = 1,
): { value: number; edgeType: 'div2' | 'triple' }[] => {
  const preds: { value: number; edgeType: 'div2' | 'triple' }[] = [];
  preds.push({ value: 2 * m, edgeType: 'div2' });
  if ((m - w) % q === 0) {
      const k = (m - w) / q;
      if (k > 0 && k % 2 === 1) {
          preds.push({ value: k, edgeType: 'triple' });
      }
  }
  return preds;
};
Enter fullscreen mode Exit fullscreen mode

To make sure no numbers are missed within visual boundaries, a second traversal pass is made. Here any odd number that is not in the graph within particular visual range is being traced forwards via regular Collatz steps until it either merges into a previously visited number or enters a cycle.

I have also tried generating this graph with various rulesets. As expected, the graph for the 5n+1 rule breaks down completely trajectories diverge and disperse into randomness.

5n+1 mess

For n+1 it looks dull because symmetrical

Just n+1

But for rulesets like the classic 3n+1, a particular shape emerges – a droplet. I must say i found this kind of surprising given the natural chaotic unpredictability of each trajectory individually.

3n+1 droplet pattern


Cause the growth of the Collatz tree is exponential, this graph requires insane amounts of ram. Even though my rig is quite weak, it has been enough to map up to 2^14..2^15 zone


A little bit later I'll share this demoscene for free

Any feedback, ideas, or critiques are highly welcome!

Top comments (0)