NAME
Math::PlanePath::DiagonalsAlternating -- points in diagonal stripes of alternating directions
SYNOPSIS
use Math::PlanePath::DiagonalsAlternating;my $path = Math::PlanePath::DiagonalsAlternating->new;my ($x, $y) = $path->n_to_xy (123);
DESCRIPTION
This path follows successive diagonals going from the Y axis down to the X axis and then back up again,
5 | 16| |\4 | 15 17| \ \3 | 7 14 18| |\ \ \2 | 6 8 13 19 ...| \ \ \ \ \1 | 2 5 9 12 20 23| |\ \ \ \ \ \Y=0 | 1 3-- 4 10--11 21--22+----------------------------X=0 1 2 3 4 5 6
The triangular numbers 1,3,6,10,etc k*(k+1)/2 are the start of each run up or down alternately on the X axis and Y axis. N=1,6,15,28,etc on the Y axis (Y even) are the hexagonal numbers j*(2j-1). N=3,10,21,36,etc on the X axis (X odd) are the hexagonal numbers of the second kind j*(2j+1).
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 => 04 | 143 | 6 132 | 5 7 121 | 1 4 8 11Y=0 | 0 2 3 9 10+-----------------X=0 1 2 3 4
FUNCTIONS
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
- "$path = Math::PlanePath::DiagonalsAlternating->new ()"
- "$path = Math::PlanePath::DiagonalsAlternating->new (n_start => $n)"
-
Create and return a new path object.
- "($x,$y) = $path->n_to_xy ($n)"
-
Return the X,Y coordinates of point number
$non the path.For
"$n < 1"the return is an empty list, it being considered the path begins at 1.
FORMULAS
Rectangle to N Range
Within each row increasing X is increasing N, and in each column increasing Y is increasing N. So in a rectangle the lower left corner is the minimum N and the upper right is the maximum N.
| N max| ----------+| | ^ || | | || | ----> || +----------| N min+-------------------
OEIS
Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include
<http://oeis.org/A131179> (etc)
n_start=1A131179 N on X axis (extra initial 0)A128918 N on Y axis (extra initial 1)A001844 N on X=Y diagonalA038722 permutation N at transpose Y,Xn_start=0A319572 X coordinateA319573 Y coordinateA319571 X,Y coordinates togetherA003056 X+YA004247 X*YA049581 abs(X-Y)A048147 X^2+Y^2A004198 X bit-and YA003986 X bit-or YA003987 X bit-xor YA004197 min(X,Y)A003984 max(X,Y)A101080 HammingDist(X,Y)A023531 dSum = dX+dY, being 1 at N=triangular+1 (and 0)A046092 N on X=Y diagonalA061579 permutation N at transpose Y,XA056011 permutation N at points by Diagonals,direction=up orderA056023 permutation N at points by Diagonals,direction=downruns alternately up and down, both are self-inverse
The coordinates such as A003056 X+Y are the same here as in the Diagonals path. "DiagonalsAlternating" transposes X,Y -> Y,X in every second diagonal but forms such as X+Y are unchanged by swapping to Y+X.
SEE ALSO
Math::PlanePath, Math::PlanePath::Diagonals, Math::PlanePath::DiagonalsOctant
HOME PAGE
<http://user42.tuxfamily.org/math-planepath/index.html>
LICENSE
Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 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/>.