NAME

Math::PlanePath::MPeaks -- points in expanding M shape

SYNOPSIS

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

DESCRIPTION

This path puts points in layers of an "M" shape

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

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

N=1 to N=5 is the first "M" shape, then N=6 to N=16 on top of that, etc. The centre goes half way down. Reckoning the N=1 to N=5 as layer d=1 then

Xleft = -d
Xright = d
Ypeak = 2*d - 1
Ycentre = d - 1

Each "M" is 6 points longer than the preceding. The verticals are each 2 longer, and the centre diagonals each 1 longer. This step 6 is similar to the HexSpiral.

The octagonal numbers N=1,8,21,40,65,etc k*(3k-2) are a straight line of slope 2 going up to the left. The octagonal numbers of the second kind N=5,16,33,56,etc k*(3k+2) are along the X axis to the right.

N Start

The default is to number points starting N=1 as shown above. An optional n_start can give a different start, in the same pattern. For example to start at 0,

n_start => 0

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

FUNCTIONS

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

$path = Math::PlanePath::MPeaks->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.

For $n < 0.5 the return is an empty list, it being considered there are no negative points.

$n = $path->xy_to_n ($x,$y)

Return the point number for coordinates $x,$y. $x and $y are each rounded to the nearest integer which has the effect of treating points as a squares of side 1, so the half-plane y>=-0.5 is entirely covered.

OEIS

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

n_start=1 (the default)
  A045944    N on X axis >= 1, extra initial 0
               being octagonal numbers second kind
  A056106    N on Y axis, extra initial 1
  A056109    N on X negative axis <= -1

n_start=0
  A049450    N on Y axis, extra initial 0, 2*pentagonal

n_start=2
  A027599    N on Y axis, extra initial 6,2

SEE ALSO

Math::PlanePath, Math::PlanePath::PyramidSides

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