Math::...ounded(3pm)

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

πŸ’– Math::PlanePath::DragonRounded πŸ’–

okay bestie, welcome to the dragon curve page!! this is Math::PlanePath::DragonRounded, a little gem from the User Contributed Perl Documentation section, and it's genuinely so iconic. it's the dragon curve, but with rounded-off corners. yes. that's the whole vibe. πŸ‰βœ¨


✨ NAME ✨

Math::PlanePath::DragonRounded β€” it's the dragon curve, but the corners are rounded, periodt. πŸ’…


✨ SYNOPSIS ✨

the classic little starter pack, no cap:

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

✨ DESCRIPTION ✨

so this is a version of the dragon curve by Harter, Heighway, et al (the OGs fr fr), except it's done with two points per edge and it skips vertices so the corners come out all rounded and soft. it's giving ✨soft launch✨ but for geometry.

                         17-16              9--8                 6
                        /     \           /     \
                      18       15       10        7              5
                       |        |        |        |
                      19       14       11        6              4
                        \        \     /           \
                         20-21    13-12              5--4        3
                              \                          \
                               22                          3     2
                                |                          |
                               23                          2     1
                              /                          /
       33-32             25-24                    .  0--1       Y=0
      /     \           /
    34       31       26                                        -1
     |        |        |
    35       30       27                                        -2
      \        \     /
       36-37    29-28    44-45                                  -3
            \           /     \
             38       43       46                               -4
              |        |        |
             39       42       47                               -5
               \     /        /
                40-41    49-48                                  -6
                        /
                      50                                        -7
                       |
                      ...

     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^
   -15-14-13-12-11-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1  2  3 ...

ok so the tea: the two points sitting on an edge have one of X or Y as a multiple of 3, and the other one (Y or X) sitting at 1 mod 3 or 2 mod 3. for example, N=19 and N=20 live on the X=-9 edge (that's a multiple of 3, slay), and they're at Y=4 and Y=5 (that's 1 and 2 mod 3 respectively πŸ’…).

and the whole point of the "rounding" of the corners is so that, for example, N=13 and N=21 don't touch when they come up on X=-6,Y=3. the curve always approaches vertices like this and never crosses itself. it's so well-behaved honestly, main character energy 🫢

Arms πŸ¦‹

the dragon curve fills a quarter of the plane, and four copies mesh together rotated by 90, 180 and 270 degrees. the arms parameter lets you pick 1 to 4 curve arms, successively advancing. like, for example, arms => 4 gives you this whole situation:

            36-32             59-...          6
           /     \           /
...      40       28       55                 5
 |        |        |        |
56       44       24       51                 4
  \     /           \        \
   52-48    13--9    20-16    47-43           3
           /     \        \        \
         17        5       12       39        2
          |        |        |        |
         21        1        8       35        1
        /                 /        /
   29-25     6--2     0--4    27-31       <- Y=0
  /        /                 /
33       10        3       23                -1
 |        |        |        |
37       14        7       19                -2
  \        \        \     /
   41-45    18-22    11-15    50-54          -3
        \        \           /     \
         49       26       46       58       -4
          |        |        |        |
         53       30       42       ...      -5
        /           \     /
...-57             34-38                   -6

 ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^
-6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6

with 4 arms like this, all 3x3 blocks get visited, using 4 out of 9 points in each. efficiency queen πŸ‘‘

Midpoint πŸ“

the points of this rounded curve correspond to the DragonMidpoint with a little squish that turns each 6x6 block into a 4x4 block. for instance, in the following, N=2,3 get pushed to the left, and N=6 through N=11 shift down and squash up horizontally. little glow-up, no big deal:

     DragonRounded               DragonMidpoint

        9--8
       /    \
     10      7                     9---8
      |      |                     |   |
     11      6                    10   7
    /         \                    |   |
               5--4      <=>     -11   6---5---4
                   \                           |
                    3                          3
                    |                          |
                    2                          2
                   /                           |
             . 0--1                        0---1

✨ FUNCTIONS ✨

peep "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes, bestie. πŸ’–

  • $path = Math::PlanePath::DragonRounded->new ()
  • $path = Math::PlanePath::DragonRounded->new (arms => $aa) β€” create and return a brand new path object. the optional arms parameter makes a multi-arm curve, and the default is 1 for just one arm. simple as that.
  • ($x,$y) = $path->n_to_xy ($n) β€” returns the X,Y coordinates of point number $n on the path. points begin at 0, and if $n < 0 then you get back an empty list. (yeah, negative N gets nothing. sorry babe. 😭)
  • $n = $path->n_start() β€” returns 0, the first N in the path. it's zero, it's humble, it's iconic. 🌸

Level Methods 🧚

  • ($n_lo, $n_hi) = $path->level_to_n_range($level) β€” returns (0, 2 * 2**$level - 1), or for multiple arms it returns (0, $arms * 2 * 2**$level - 1).

and the math tea: there are 2^level segments comprising the dragon, or arms*2^level when you've got multiple arms. each one has 2 points in this rounded curve, numbered starting from 0. so many points, all accounted for πŸ’…


✨ FORMULAS ✨

X,Y to N πŸ”₯

the correspondence with the DragonMidpoint we mentioned above means you can just use that module's method for the rounded xy_to_n(). lowkey convenient.

basically, the correspondence reckons each point on the rounded curve as the midpoint of a dragon curve of one greater level of detail, plus segments on 45-degree angles. it's giving "same energy, different outfit."

the coordinate conversion turns each 6x6 block of DragonRounded into a 4x4 block of DragonMidpoint. and there's no rotations or anything β€” it's chill like that:

Xmid = X - floor(X/3) - Xadj[X%6][Y%6]
Ymid = Y - floor(Y/3) - Yadj[X%6][Y%6]

N = DragonMidpoint n_to_xy of Xmid,Ymid

Xadj[][] is a 6x6 table of 0 or 1 or undef
Yadj[][] is a 6x6 table of -1 or 0 or undef

and honestly? the Xadj,Yadj tables are a handy place to notice X,Y points that aren't on the DragonRounded style 4 of 9 points. or 16 of 36 points if you wanna count it that way, since the tables are 6x6. math girlies rise ✨


✨ OEIS ✨

entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include the various DragonCurve sequences at even N, and in addition:

<http://oeis.org/A152822> (etc)

A152822   abs(dX), so 0=vertical,1=not, being 1,1,0,1 repeating
A166486   abs(dY), so 0=horizontal,1=not, being 0,1,1,1 repeating

✨ SEE ALSO ✨

  • Math::PlanePath
  • Math::PlanePath::DragonCurve
  • Math::PlanePath::DragonMidpoint
  • Math::PlanePath::TerdragonRounded

(the whole squad 🫢)


✨ 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. slay, go off, share the code πŸ’–

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. (that's the serious bit, bestie β€” no warranty, fr fr, don't come for anyone if it breaks 😭)

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


and that's the whole page!! πŸŽ€ this was perl v5.32.0, dated 2021-01-23, and yeah β€” the manual name at the top and bottom is the same Math::...ounded(3pm) vibe, but you already knew that, iykyk. go make some rounded dragon curves, you absolute icon πŸ‘‘πŸ’œβœ¨