Math::...agonals(3pm)

๐Ÿ“ฆ
version 129 ยท 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– Math::PlanePath::PeanoDiagonals ๐Ÿ’–

okay bestie, welcome to the User Contributed Perl Documentation corner of the internet, where we're talking about Math::PlanePath::PeanoDiagonals โ€” a 3x3 self-similar quadrant traversal across squares. it's giving fractal royalty, no cap. ๐Ÿ‘‘


โœจ NAME โœจ

Math::PlanePath::PeanoDiagonals โ€” a 3x3 self-similar quadrant traversal across squares. that's the whole vibe. ๐ŸŒธ


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

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

# or another radix digits ...
my $path5 = Math::PlanePath::PeanoDiagonals->new (radix => 5);

like, that's it. that's the whole entrance exam. ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so this path is the Peano curve, except the segments go diagonally across unit squares instead of down the middle. main character behavior, honestly.

the source material, for the academically inclined besties:

Giuseppe Peano, "Sur Une Courbe, Qui Remplit Toute Une Aire Plane", Mathematische Annalen, volume 36, number 1, 1890, pages 157-160. DOI 10.1007/BF01199438. <https://link.springer.com/article/10.1007/BF01199438>, <https://eudml.org/doc/157489>

points N sit at each corner of the squares, which means all the locations are even, as in (X+Y even). here's the whole grid, look at her:

     9 |    61,425      63,423      65,421      79,407      81,405
     8 | 60       58,62       64,68       66,78       76,80
     7 |    55,59       57,69       67,71       73,77       75,87
     6 | 54       52,56       38,70       36,72       34,74
     5 |    49,53       39,51       37,41       31,35       33,129
     4 | 48       46,50       40,44       30,42       28,32
     3 |     7,47        9,45       11,43       25,29       27,135
     2 |  6        4,8        10,14       12,24       22,26
     1 |     1,5         3,15       13,17       19,23       21,141
   Y=0 |  0         2          16          18          20
       +----------------------------------------------------------
        X=0   1     2     3     4     5     6     7     8     9

Moore (figure 3) draws this form, though here it's transposed so the first unit squares go East. slay. ๐Ÿงญ

E. H. Moore, "On Certain Crinkly Curves", Transactions of the American Mathematical Society, volume 1, number 1, 1900, pages 72-90. <http://www.ams.org/journals/tran/1900-001-01/S0002-9947-1900-1500526-4/>, <http://www.ams.org/journals/tran/1900-001-04/S0002-9947-1900-1500428-3/>

and the segments between the initial points can be illustrated like this, she's so intricate:

      |    \              \
      +--- 47,7 ----+--- 45,9 --
      |    ^ | \    |   ^  | \
      |  /   |  \   |  /   |  v
      | /    |   v  | /    |  ...
      6 -----+---- 4,8 ----+--
      | ^    |    / | ^    |
      |   \  |   /  |   \  |
      |    \ | v    |    \ |
      +-----5,1 ----+---- 3,15
      |   ^  | \    |   ^  |
      |  /   |  \   |  /   |
      | /    |   v  | /    |
    N=0------+------2------+--

so segment N=0 to N=1 goes from the origin X=0,Y=0 up to X=1,Y=1, then N=2 is down again to X=2,Y=0, and so on forever. the plain PeanoCurve is the middle of each square, so the points here are N + 1/2 (and you reckon the first such midpoint as the origin).

the rule for block reversals is described over with PeanoCurve. N gets split to an X and a Y digit alternately. if the sum of Y digits above is odd then the X digit is reversed, and vice versa โ€” X odd means Y reversed. keep up bestie ๐Ÿซถ

a plain diagonal is North-East per N=0 to 1. diagonals get mirrored according to the final sum of all digits:

  • if the sum of Y digits is odd โ†’ mirror horizontally
  • if the sum of X digits is odd โ†’ mirror vertically

and that mirroring is X+1 and/or Y+1 as compared to the plain PeanoCurve.

an integer N is at the start of the segment with its final reversal. fractional N follows the diagonal across its unit square. ๐ŸŒˆ

as noted above, all locations are even (X+Y even). those on the axes are visited once, and all others twice.

๐Ÿ’Ž Diamond Shape ๐Ÿ’Ž

some authors take this diagonals form and rotate it -45 degrees so the segments are X,Y aligned, and the pattern fills a wedge shape between diagonals X=Y and X=-Y (for X>=0). iconic angle honestly.

         6----7,47
         |     |
         |     |
    0---1,5---4,8---9,45
         |     |     |
         |     |    ...
         2----3,15

in terms of the coordinates here, this is (X+Y)/2, (Y-X)/2.

๐Ÿ“ Even Radix ๐Ÿ“

in an even radix, the mirror rule for diagonals across unit squares is applied the same way. but โ€” plot twist โ€” in this case the end of one segment does not always coincide with the start of the next. ๐Ÿ˜ญ

      +---15,125----+---13,127-- 16 -----+----18,98-
      |   /  | ^    |   /  | ^    | \    |   ^  | \
      |  /   |  \   |  /   |  \   |  \   |  /   |  \
      | v    |   \  | v    |   \  |   v  | /    |   v
      +----- 9 --- 14 --- 11 --- 12 --- 17 -----+--  ...
      |    ^ | \    |   ^  | \    |
      |  /   |  \   |  /   |  \   |
      | /    |   v  | /    |    v |
      8 ---- 7 --- 10 ---- 5 -----+---
      |   /  | ^    |   /  | ^    |
      |  /   |  \   |  /   |  \   |         radix => 4
      | v    |   \  | v    |   \  |
      +----- 1 ---- 6 ---- 3 ---- 4 --
      |   ^  | \    |   ^  | \    |
      |  /   |  \   |  /   |  \   |
      | /    |   v  | /    |   v  |
    N=0------+----- 2 -----+------+---

so: the first row N=0 to N=3 goes left to right. the next row N=4 to N=7 is a horizontal mirror image, so it goes right to left. N = 3.99.. < 4 follows its diagonal across its unit square, so it approaches X=3.99,Y=0. and then โ€” boom โ€” there's a discontinuity up to N=4 at X=4,Y=1. ๐Ÿ’€

block N=0 to N=15 repeats starting N=16, with a vertical mirror image. there's an even bigger discontinuity between N=15 to N=16 (like there is in even radix PeanoCurve).

some double-visited points occur, such as N=15 and N=125 both at X=1,Y=4. this is when the 4x16 block N=0 to 64 is copied above, mirrored horizontally. iykyk. ๐Ÿชž


๐Ÿ”ฅ FUNCTIONS ๐Ÿ”ฅ

see "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes, bestie โ€” that's the shared lore.

  • $path = Math::PlanePath::PeanoDiagonals->new ()
  • $path = Math::PlanePath::PeanoDiagonals->new (radix => $r) โ€” create and return a new path object. the optional radix parameter gives the base for digit splitting, and the default is ternary, radix => 3. cute and simple. โœจ
  • ($x,$y) = $path->n_to_xy ($n) โ€” return the X,Y coordinates of point number $n on the path. points begin at 0, and if $n < 0 then the return is an empty list. fractional $n gives an X,Y position along the diagonals across unit squares. ๐ŸŒธ
  • ($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2) โ€” return a range of N values which covers the rectangle with corners at $x1,$y1 and $x2,$y2. if the X,Y values are not integers then the curve is treated as unit squares centred on each integer point, and squares which are partly covered by the given rectangle are included.
in the current implementation, the returned range is an over-estimate, so $n_lo might be smaller than the smallest actually in the rectangle, and $n_hi bigger than the actual biggest. generous queen. ๐Ÿ‘‘

๐ŸŒŸ Level Methods ๐ŸŒŸ

  • ($n_lo, $n_hi) = $path->level_to_n_range($level) โ€” return (0, $radix**(2*$level) - 1). that's the whole thing, no notes. ๐Ÿ’…

๐Ÿงฎ FORMULAS ๐Ÿงฎ

๐Ÿ’ซ N to Turn ๐Ÿ’ซ

the curve turns left or right 90 degrees at each point N >= 1. the turn is 90 degrees:

turn(N) = (-1)^(N + number of low ternary 0s of N)
        = -1,1,1,1,-1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,-1,1
by 90 degrees (+1 left, -1 right)

the power of -1 means left or right flip for each low ternary 0 of N, and flip again if N is odd. odd N is an odd number of ternary 1 digits. math is mathing fr fr. ๐Ÿ”ข

this formula follows from the turns in a new low base-9 digit. for a segment crossing a given unit square, the expanded segments have the same start and end directions, so the existing turns, now 9*N, are unchanged. then 9*N+r goes as r in the base figure, but flipped L<->R when N is odd, since blocks are mirrored alternately.

turn(9N)   = turn(N)
turn(9N+r) = turn(r)*(-1)^N         for  1 <= r <= 8

or in terms of base 3, a single new low ternary digit is a transpose of what's above, and the base figure turns r=1,2 are L<->R when the N above is odd.

turn(3N)   = - turn(N)
turn(3N+r) = turn(r)*(-1)^N         for r = 1 or 2

similarly in any odd radix. periodt. ๐Ÿ’…


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • Math::PlanePath
  • Math::PlanePath::PeanoCurve
  • Math::PlanePath::HilbertSides

๐ŸŒˆ HOME PAGE ๐ŸŒˆ

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


๐Ÿ“œ LICENSE ๐Ÿ“œ

Copyright 2019, 2020 Kevin Ryde

this file is part of Math-PlanePath.

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/>.


and that's the whole page bestie, you ate it up ๐Ÿซถ this was perl v5.32.0, dated 2021-01-23, straight from the Math::...agonals(3pm) corner of the docs. go draw some diagonals. ๐Ÿ’–โœจ๐ŸŽ€