NAME

Math::PlanePath::ComplexPlus -- points in complex base i+r

SYNOPSIS

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

DESCRIPTION

This path traverses points by a complex number base i+r for integer r>=1. The default is base i+1

                     30  31          14  15                 5
                 28  29          12  13                     4
                     26  27  22  23  10  11   6   7         3
                 24  25  20  21   8   9   4   5             2
     62  63          46  47  18  19           2   3         1
 60  61          44  45  16  17           0   1         <- Y=0
     58  59  54  55  42  43  38  39                        -1
 56  57  52  53  40  41  36  37                            -2
             50  51  94  95  34  35  78  79                -3
         48  49  92  93  32  33  76  77                    -4
                     90  91  86  87  74  75  70  71        -5
                 88  89  84  85  72  73  68  69            -6
    126 127         110 111  82  83          66  67        -7
124 125         108 109  80  81          64  65            -8
    122 123 118 119 106 107 102 103                        -9
120 121 116 117 104 105 100 101                           -10
            114 115          98  99                       -11
        112 113          96  97                           -12

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

The shape of these points N=0 to N=2^k-1 inclusive is equivalent to the twindragon turned 135 degrees. Each complex base point corresponds to a unit square inside the twindragon curve (two DragonCurve back-to-back).

Real Part

Option realpart => $r selects another r for complex base b=i+r. For example

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

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

N is broken into digits of a base norm=r*r+1, ie. digits 0 to r*r inclusive.

norm = r*r + 1
Nstart = 0
Nlevel = norm^level - 1

The low digit of N makes horizontal runs of r*r+1 many points, such as N=0 to N=4, then N=5 to N=9, etc shown above. In the default r=1 these runs are 2 long. For r=2 shown above they're 2*2+1=5 long, or r=3 would be 3*3+1=10, etc.

The offset for each successive run is i+r, ie. Y=1,X=r such as at N=5 shown above. Then the offset for the next level is (i+r)^2 = (2r*i + r^2-1) so N=25 begins at Y=2*r=4, X=r*r-1=3. In general each level adds an angle

angle = atan(1/r)
Nlevel_angle = level * angle

So the points spiral around anti-clockwise. For r=1 the angle is atan(1/1)=45 degrees, so that for example level=4 is angle 4*45=180 degrees, putting N=2^4=16 on the negative X axis as shown in the first sample above.

As r becomes bigger the angle becomes smaller, making it spiral more slowly. The points never fill the plane, but the set of points N=0 to Nlevel are all touching.

Arms

For realpart => 1, an optional arms => 2 adds a second copy of the curve rotated 180 degrees and starting from X=0,Y=1. It meshes perfectly to fill the plane. Each arm advances successively so N=0,2,4,etc is the plain path and N=1,3,5,7,etc is the copy

arms=>2

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

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

There's no arms parameter for other realpart values as yet, only for i+1. Is there a good rotated arrangement for others? Do "norm" many copies fill the plane in general?

FUNCTIONS

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

$path = Math::PlanePath::ComplexPlus->new ()

Create and return a new path object.

($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.

Level Methods

($n_lo, $n_hi) = $path->level_to_n_range($level)

Return (0, 2**$level - 1), or for 2 arms return (0, 2 * 2**$level - 1). With the realpart option return (0, $norm**$level - 1) where norm=realpart^2+1.

FORMULAS

Various formulas and pictures etc for the i+1 case can be found in the author's long mathematical write-up (section "Complex Base i+1")

OEIS

Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include

realpart=1 (i+1, the default)
  A290885    -X
  A290884    Y
  A290886    norm X^2 + Y^2
  A146559    dX at N=2^k-1 (step to next replication level)
  A077950,A077870
           location of ComplexMinus origin in ComplexPlus
           (mirror horizontal even level, vertical odd level)

SEE ALSO

Math::PlanePath, Math::PlanePath::ComplexMinus, Math::PlanePath::ComplexRevolving, Math::PlanePath::DragonCurve

HOME PAGE

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

LICENSE

Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 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/>.