Math::...slands(3pm)

πŸ“¦
version 129 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Math::PlanePath::GosperIslands πŸ’–

okay bestie, sit down, hydrate, because we are diving into Math::PlanePath::GosperIslands, straight out of the Perl user-contributed documentation. this one's all about concentric Gosper islands and honestly it's giving geometry royalty. πŸ¦‹


✨ NAME ✨

Math::PlanePath::GosperIslands β€” concentric Gosper islands. that's it, that's the name, no cap. πŸ’…


✨ SYNOPSIS ✨

use Math::PlanePath::GosperIslands;
my $path = Math::PlanePath::GosperIslands->new;
my ($x, $y) = $path->n_to_xy (123);

✨ DESCRIPTION ✨

so this path is literally the integer versions of the Gosper island at successive levels, arranged as concentric rings on a triangular lattice (peep "Triangular Lattice" in Math::PlanePath for that one). each island is the outline of a self-similar tiling of the plane by hexagons, and the sides are self-similar expansions of line segments. πŸŽ€

             35----34                                           8
            /        \
       ..-36          33----32          29----28                7
                              \        /        \
                               31----30          27----26       6
                                                         \
                                                          25    5

                                                       78       4
                                                         \
                      11-----10                           77    3
                     /         \                         /
             13----12           9---- 8                76       2
            /                          \                 \
          14           3---- 2           7                ...   1
            \        /        \
             15     4           1    24                     <- Y=0
            /        \                 \
          16           5----- 6         23                     -1
            \                          /
             17----18          21----22                        -2
                     \        /
                      19----20                                 -3

          -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7  8  9 10 11

🌸 Hexagon Replications 🌸

the islands can be thought of as a self-similar tiling of the plane by hexagonal shapes. the innermost hexagon N=1 to N=6 is replicated six times to make the next outline N=7 to N=24. iconic behaviour fr fr.

                   *---*
                  /     \
             *---*       *---*
            /     \     /     \
           *       *---*       *
            \     /     \     /
             *---*       *---*
            /     \     /     \
           *       *---*       *
            \     /     \     /
             *---*       *---*
                  \     /
                   *---*

then that shape is in turn replicated six times around itself to make the next level. the math is mathing. ✨

                           *---E
                          /     \
                     *---*       *---*       *---*
                    /                 \     /     \
                   *                   *---*       *---*
                    \                 /                 \
                     *               *                   D
                    /                 \                 /
               *---*                   *               *
              /     \                 /                 \
         *---*       *---*       *---*                   *
        /                 \     /     \                 /
       *                   *---*       *---*       *---*
        \                 /                 \     /     \
         *               *                   C---*       *---*
        /                 \                 /                 \
       *                   *       O       *                   *
        \                 /                 \                 /
         *---*       *---*                   *               *
              \     /     \                 /                 \
               *---*       *---*       *---*                   *
              /                 \     /     \                 /
             *                   *---*       *---*       *---*
              \                 /                 \     /
               *               *                   *---*
              /                 \                 /
             *                   *               *
              \                 /                 \
               *---*       *---*                   *
                    \     /     \                 /
                     *---*       *---*       *---*
                                      \     /
                                       *---*

the shapes here and at higher level are like hexagons with wiggly sides. the sides are symmetric, so they mate on opposite sides, but the join "corner" is not on the X axis (after the first level). for example the point marked "C" (N=7) is above the axis at X=5,Y=1. the next replication joins at point "D" (N=25) at X=11,Y=5. lowkey obsessed with the precision here. πŸ’…

πŸ¦‹ Side and Radial Lines πŸ¦‹

the sides at each level is a self-similar line segment expansion,

                                    *---*
         *---*     becomes         /
                              *---*

this expanding side shape is also the radial line or spoke from the origin out to "corner" join points. at level 0 they're straight lines,

          ...----*
                / \
               /   \ side
              /     \
             /       \
            O---------*
                     /
                    /

then at higher levels they're wiggly, such as level 1,

       ...--*
           / \
          *   *---*
           \       \
            *   *---C
           /   /   /
          O---*   ...

or level 2,

            *---E
         ...   / \
              *   *---*       *---*
               \       \     /     \
                *       *---*       *---*
               /                         \
              *                       *---D
               \                     /   /
                *---*           *---*   ...
                     \         /
                      *       *
                     /         \
                    *           *
                     \         /
                      *   *---C
                     /   /
                    O---*

the lines become ever wigglier at higher levels, and in fact become "S" shapes with the ends spiralling around and in (and in fact middle sections likewise S and spiralling, to a lesser extent). the drama of it all. 😭

the spiralling means that the X axis is crossed multiple times at higher levels. for example in level 11 X>0,Y=0 occurs 22 times between N=965221 and N=982146. likewise on diagonal lines X=Y and X=-Y which are "sixths" of the initial hexagon.

the self-similar spiralling means the Y axis too is crossed multiple times at higher levels. in level 11 again X=0,Y>0 is crossed 7 times between N=1233212 and N=1236579. (those N's are bigger than the X axis crossing, because the Nstart position at level 11 has rotated around some 210 degrees to just under the negative X axis.) bestie that's a lot of crossing. πŸ™ˆ

in general any radial straight line is crossed many times way eventually.

🌈 Level Ranges 🌈

counting the inner hexagon as level=0, the side length and whole ring is

       sidelen = 3^level
       ringlen = 6 * 3^level

the starting N for each level is the total points preceding it, so

       Nstart = 1 + ringlen(0) + ... + ringlen(level-1)
              = 3^(level+1) - 2

for example level=2 starts at Nstart=3^3-2=25.

the way the side/radial lines expand as described above makes the Nstart position rotate around at each level. N=7 is at X=5,Y=1 which is angle

       angle = arctan(1*sqrt(3) / 5)
             = 19.106.. degrees

the sqrt(3) factor as usual turns the flattened integer X,Y coordinates into proper equilateral triangles. the further levels are then multiples of that angle. for example N=25 at X=11,Y=5 is 2*angle, or N=79 at X=20,Y=18 at 3*angle.

the N=7 which is the first radial replication at X=5,Y=1, scaled to unit sided equilateral triangles, has distance from the origin

       d1 = hypot(5, 1*sqrt(3)) / 2
          = sqrt(7)

the subsequent levels are powers of that sqrt(7),

       Xstart,Ystart of the Nstart(level) position

       d = hypot(Xstart,Ystart*sqrt(3))/2
         = sqrt(7) ^ level

this multiple of the angle and powering of the radius means the Nstart points are on a logarithmic spiral. slay. πŸ’œ

πŸŽ€ Fractal Island πŸŽ€

the Gosper island is usually conceived as a fractal, with the initial hexagon in a fixed position and the sides having the line segment substitution described above, for ever finer levels of "S" spiralling wiggliness. the code here can be used for that by rotating the Nstart position back to the X axis and scaling down to a desired unit radius.

       Xstart,Ystart of the Nstart(level) position

       scale factor = 0.5 / hypot(Ystart*sqrt(3), Xstart)
       rotate angle = - atan2 (Ystart*sqrt(3), Xstart)

this scale and rotate puts the Nstart point at X=1,Y=0 and further points of the ring around from that. remember the sqrt(3) factor on Y for all points to turn the integer coordinates into proper equilateral triangles.

notice the line segment substitution doesn't change the area of the initial hexagon. effectively (and not to scale),

                                    *
                                   / \
       *-------*    becomes   *   /   *
                               \ /
                                *

so the area lost below is gained above (or vice versa). the result is a line of ever greater length enclosing an unchanging area. conservation of area but make it ✨fractal✨.


✨ FUNCTIONS ✨

peep "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.

  • $path = Math::PlanePath::GosperIslands->new () β€” create and return a new path object. baby's first path object. 🫢
  • ($x,$y) = $path->n_to_xy ($n) β€” return the X,Y coordinates of point number $n on the path. points begin at 1 and if $n < 0 then the return is an empty list. note that, bestie, 1 not 0. πŸ’…

✨ SEE ALSO ✨

Math::PlanePath, Math::PlanePath::KochSnowflakes, Math::PlanePath::GosperSide


✨ HOME PAGE ✨

<http://user42.tuxfamily.org/math-planepath/index.html>


✨ LICENSE ✨

Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde

Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.

real talk: that warranty disclaimer is doing heavy lifting, so read it, don't skip it. no warranty, fr fr. 😭

and that's the whole page, bestie! this one came to you from perl v5.32.0, dated 2021-01-23, and it's the Math::...slands(3pm) manual. now go forth and spiral logarithmically. πŸ’–βœ¨πŸ¦‹