1Math::PlanePath::DiagonUaslesrAlCtoenrtnraitbiuntge(d3M)Paetrhl::DPolcaunmeePnattaht:i:oDniagonalsAlternating(3)
2
3
4
6 Math::PlanePath::DiagonalsAlternating -- points in diagonal stripes of
7 alternating directions
8
10 use Math::PlanePath::DiagonalsAlternating;
11 my $path = Math::PlanePath::DiagonalsAlternating->new;
12 my ($x, $y) = $path->n_to_xy (123);
13
15 This path follows successive diagonals going from the Y axis down to
16 the X axis and then back up again,
17
18 5 | 16
19 | |\
20 4 | 15 17
21 | \ \
22 3 | 7 14 18
23 | |\ \ \
24 2 | 6 8 13 19 ...
25 | \ \ \ \ \
26 1 | 2 5 9 12 20 23
27 | |\ \ \ \ \ \
28 Y=0 | 1 3-- 4 10--11 21--22
29 +----------------------------
30 X=0 1 2 3 4 5 6
31
32 The triangular numbers 1,3,6,10,etc k*(k+1)/2 are the start of each run
33 up or down alternately on the X axis and Y axis. N=1,6,15,28,etc on
34 the Y axis (Y even) are the hexagonal numbers j*(2j-1).
35 N=3,10,21,36,etc on the X axis (X odd) are the hexagonal numbers of the
36 second kind j*(2j+1).
37
38 N Start
39 The default is to number points starting N=1 as shown above. An
40 optional "n_start" can give a different start, in the same pattern.
41 For example to start at 0,
42
43 n_start => 0
44
45 4 | 14
46 3 | 6 13
47 2 | 5 7 12
48 1 | 1 4 8 11
49 Y=0 | 0 2 3 9 10
50 +-----------------
51 X=0 1 2 3 4
52
54 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
55 classes.
56
57 "$path = Math::PlanePath::DiagonalsAlternating->new ()"
58 "$path = Math::PlanePath::DiagonalsAlternating->new (n_start => $n)"
59 Create and return a new path object.
60
61 "($x,$y) = $path->n_to_xy ($n)"
62 Return the X,Y coordinates of point number $n on the path.
63
64 For "$n < 1" the return is an empty list, it being considered the
65 path begins at 1.
66
68 Rectangle to N Range
69 Within each row increasing X is increasing N, and in each column
70 increasing Y is increasing N. So in a rectangle the lower left corner
71 is the minimum N and the upper right is the maximum N.
72
73 | N max
74 | ----------+
75 | | ^ |
76 | | | |
77 | | ----> |
78 | +----------
79 | N min
80 +-------------------
81
83 Entries in Sloane's Online Encyclopedia of Integer Sequences related to
84 this path include
85
86 <http://oeis.org/A131179> (etc)
87
88 n_start=1
89 A131179 N on X axis (extra initial 0)
90 A128918 N on Y axis (extra initial 1)
91 A001844 N on X=Y diagonal
92 A038722 permutation N at transpose Y,X
93
94 n_start=0
95 A319572 X coordinate
96 A319573 Y coordinate
97 A319571 X,Y coordinates together
98 A003056 X+Y
99 A004247 X*Y
100 A049581 abs(X-Y)
101 A048147 X^2+Y^2
102 A004198 X bit-and Y
103 A003986 X bit-or Y
104 A003987 X bit-xor Y
105 A004197 min(X,Y)
106 A003984 max(X,Y)
107 A101080 HammingDist(X,Y)
108 A023531 dSum = dX+dY, being 1 at N=triangular+1 (and 0)
109 A046092 N on X=Y diagonal
110 A061579 permutation N at transpose Y,X
111
112 A056011 permutation N at points by Diagonals,direction=up order
113 A056023 permutation N at points by Diagonals,direction=down
114 runs alternately up and down, both are self-inverse
115
116 The coordinates such as A003056 X+Y are the same here as in the
117 Diagonals path. "DiagonalsAlternating" transposes X,Y -> Y,X in every
118 second diagonal but forms such as X+Y are unchanged by swapping to Y+X.
119
121 Math::PlanePath, Math::PlanePath::Diagonals,
122 Math::PlanePath::DiagonalsOctant
123
125 <http://user42.tuxfamily.org/math-planepath/index.html>
126
128 Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
129 2020, 2021 Kevin Ryde
130
131 This file is part of Math-PlanePath.
132
133 Math-PlanePath is free software; you can redistribute it and/or modify
134 it under the terms of the GNU General Public License as published by
135 the Free Software Foundation; either version 3, or (at your option) any
136 later version.
137
138 Math-PlanePath is distributed in the hope that it will be useful, but
139 WITHOUT ANY WARRANTY; without even the implied warranty of
140 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
141 General Public License for more details.
142
143 You should have received a copy of the GNU General Public License along
144 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
145
146
147
148perl v5.34.0 2022-M0a1t-h2:1:PlanePath::DiagonalsAlternating(3)