Kevin Ryde > Math-PlanePath > Math::PlanePath::KochSquareflakes

Download:
Math-PlanePath-116.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

Open  2
View/Report Bugs
Module Version: 116   Source  

NAME ^

Math::PlanePath::KochSquareflakes -- four-sided Koch snowflakes

SYNOPSIS ^

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

DESCRIPTION ^

This is the Koch curve shape arranged as four-sided concentric snowflakes.

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

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

The innermost square N=1 to N=4 is the initial figure. Its sides expand as the Koch curve pattern in subsequent rings. The initial figure is on X=+/-0.5,Y=+/-0.5 fractions. The points after that are integer X,Y.

Inward ^

The inward=>1 option can direct the sides inward. The shape and lengths etc are the same. The angles and sizes mean there's no overlaps.

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

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

Level Ranges

Counting the innermost N=1 to N=4 square as level 0, a given level has

    looplen = 4*4^level

many points. The start of a level is N=1 plus the preceding loop lengths so

    Nstart = 1 + 4*[ 1 + 4 + 4^2 + ... + 4^(level-1) ]
           = 1 + 4*(4^level - 1)/3
           = (4^(level+1) - 1)/3

and the end of a level similarly the total loop lengths, or simply one less than the next Nstart,

    Nend = 4 * [ 1 + ... + 4^level ]
         = (4^(level+2) - 4) / 3

         = Nstart(level+1) - 1

For example,

    level  Nstart   Nend
      0       1       4
      1       5      20
      2      21      84
      3      85     340

The Xstart,Ystart position of the Nstart corner is a Lucas sequence,

    Xstart(0) = -0.5
    Xstart(1) = -2
    Xstart(2) = 4*Xstart(1) - 2*Xstart(0) = -7
    Xstart(3) = 4*Xstart(2) - 2*Xstart(1) = -24
    ...
    Xstart(level+1) = 4*Xstart(level) - 2*Xstart(level-1)

    0.5, 2, 7, 24, 82, 280, 956, 3264, ...

This recurrence occurs because the replications are 4 wide when horizontal but 3 wide when diagonal.

FUNCTIONS ^

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

$path = Math::PlanePath::KochSquareflakes->new ()
$path = Math::PlanePath::KochSquareflakes->new (inward => $bool)

Create and return a new path object.

OEIS ^

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

http://oeis.org/A003480 (etc)

    A003480    -X,-Y coordinate first point of each ring
               likewise A020727
    A007052    X,Y coordinate of axis crossing,
               and also maximum height of a side
    A072261    N on Y negative axis (half way along first side)
    A206374    N on South-East diagonal (end of first side)

SEE ALSO ^

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

HOME PAGE ^

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

LICENSE ^

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

syntax highlighting: