1Math::PlanePath::CornerUAsletrerCnoanttirnigb(u3t)ed PerMlatDho:c:uPmleannteaPtaitohn::CornerAlternating(3)
2
3
4

NAME

6       Math::PlanePath::CornerAlternating -- points shaped around a corner
7       alternately
8

SYNOPSIS

10        use Math::PlanePath::CornerAlternating;
11        my $path = Math::PlanePath::CornerAlternating->new;
12        my ($x, $y) = $path->n_to_xy (123);
13

DESCRIPTION

15       This path is points in layers around a square outwards from a corner in
16       the first quadrant, alternately upward or downward.  Each row/column
17       "gnomon" added to a square makes a one-bigger square.
18
19             4 | 17--18--19--20--21 ...
20               |  |               |   |
21             3 | 16--15--14--13  22  29
22               |              |   |   |
23             2 |  5---6---7  12  23  28
24               |  |       |   |   |   |
25             1 |  4---3   8  11  24  27
26               |      |   |   |   |   |
27           Y=0 |  1---2   9--10  25--26
28               +-------------------------
29                X=0   1   2   3   4   5
30
31       This is like the Corner path, but here gnomons go back and forward and
32       in particular so points are always a unit step apart.
33
34   Wider
35       An optional "wider => $integer" makes the path wider horizontally,
36       becoming a rectangle.  For example
37
38            4  |  29--30--31--32--33--34--35--36  ...
39               |   |                           |   |
40            3  |  28--27--26--25--24--23--22  37  44      wider => 3
41               |                           |   |   |
42            2  |  11--12--13--14--15--16  21  38  43
43               |   |                   |   |   |   |
44            1  |  10---9---8---7---6  17  20  39  42
45               |                   |   |   |   |   |
46           Y=0 |   1---2---3---4---5  18--19  40--41
47               +--------------------------------------
48                 X=0   1   2   3   4   5   6   7   8
49
50       Each gnomon has the horizontal part "wider" many steps longer.  For
51       wider=3 shown, the additional points are 2,3,4 in the first row, then
52       5..10 are the next gnomon.  Each gnomon is still 2 longer than the
53       previous since this widening is a constant amount in each.
54
55   N Start
56       The default is to number points starting N=1 as shown above.  An
57       optional "n_start" can give a different start with the same shape etc.
58       For example to start at 0,
59
60             4  |  16  17  18  19  20
61             3  |  15  14  13  12  21      n_start => 0
62             2  |   4   5   6  11  22
63             1  |   3   2   7  10  23
64           Y=0  |   0   1   8   9  24
65                 ---------------------
66                  X=0   1   2   3   4
67
68       With Nstart=0, the pronic numbers are on the X=Y leading diagonal.
69

FUNCTIONS

71       See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
72       classes.
73
74       "$path = Math::PlanePath::CornerAlternating->new ()"
75       "$path = Math::PlanePath::CornerAlternating->new (wider => $w, n_start
76       => $n)"
77           Create and return a new path object.
78
79       "($x,$y) = $path->n_to_xy ($n)"
80           Return the X,Y coordinates of point number $n on the path.
81
82           For "$n < n_start()" the return is an empty list.  Fractional $n
83           gives an X,Y position along a straight line between the integer
84           positions.
85
86       "$n = $path->xy_to_n ($x,$y)"
87           Return the point number for coordinates "$x,$y".
88
89           $x and $y are each rounded to the nearest integer, which has the
90           effect of treating each point as a square of side 1, so the
91           quadrant x>=-0.5 and y>=-0.5 is entirely covered.
92
93       "($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)"
94           The returned range is exact, meaning $n_lo and $n_hi are the
95           smallest and biggest in the rectangle.
96

FORMULAS

98       Most calculations are similar to the Corner path (without the 0.5
99       fractional part), and a reversal applied when the d gnomon number is
100       odd.  When wider>0, that reversal must allow for the horizontals and
101       verticals different lengths.
102
103   Rectangle N Range
104       For "rect_to_n_range()", the largest gnomon is either the top or right
105       of the rectangle, depending where the top right corner x2,y2 falls
106       relative to the leading diagonal,
107
108           |  A---B /    x2<y2         |       /       x2>y2
109           |  |   |/     top           |  +------B     right
110           |  |   |      row           |  |  /   |     side
111           |  |  /|     biggest        |  | /    |     biggest
112           |  +---+     gnomon         |  +------C     gnomon
113           |   /                       |  /
114           +---------                  +-----------
115
116       Then the maximum is at A or B, or B or C according as which way that
117       gnomon goes, so odd or even.
118
119       If it happens that B is on the diagonal, so x2=y2, then it's either A
120       or C according as the gnomon odd or even
121
122           |        /
123           |  A----+     x2=y2
124           |  |   /|
125           |  |  / |
126           |  +----C
127           |   /
128           +-----------
129
130       For wider > 0, the diagonal shifts across so that x2-wider <=> y2 is
131       the relevant test.
132

OEIS

134       This path is in Sloane's Online Encyclopedia of Integer Sequences as,
135
136           <http://oeis.org/A319289> (etc)
137
138           wider=0, n_start=1 (the defaults)
139             A220603    X+1 coordinate
140             A220604    Y+1 coordinate
141             A213088    X+Y sum
142             A081346    N on X axis
143             A081345    N on Y axis
144             A002061    N on X=Y diagonal, extra initial 1
145             A081344    permutation N by diagonals
146             A194280      inverse
147             A020703    permutation N at transpose Y,X
148
149             A027709    boundary length of N unit squares
150             A078633    grid sticks of N points
151
152           n_start=0
153             A319290    X coordinate
154             A319289    Y coordinate
155             A319514    Y,X coordinate pairs
156             A329116    X-Y diff
157             A053615    abs(X-Y) diff
158             A000196    max(X,Y), being floor(sqrt(N))
159             A339265    dX-dY increments (runs +1,-1)
160             A002378    N on X=Y diagonal, pronic numbers
161             A220516    permutation N by diagonals
162
163           n_start=2
164             A014206    N on X=Y diagonal, pronic+2
165
166           wider=1, n_start=1
167             A081347    N on X axis
168             A081348    N on Y axis
169             A080335    N on X=Y diagonal
170             A093650    permutation N by diagonals
171
172           wider=1, n_start=0
173             A180714    X-Y diff
174
175           wider=2, n_start=1
176             A081350    N on X axis
177             A081351    N on Y axis
178             A081352    N on X=Y diagonal
179             A081349    permutation N by diagonals
180

SEE ALSO

182       Math::PlanePath, Math::PlanePath::Corner,
183       Math::PlanePath::DiagonalsAlternating
184

HOME PAGE

186       <http://user42.tuxfamily.org/math-planepath/index.html>
187

LICENSE

189       Copyright 2021 Kevin Ryde
190
191       This file is part of Math-PlanePath.
192
193       Math-PlanePath is free software; you can redistribute it and/or modify
194       it under the terms of the GNU General Public License as published by
195       the Free Software Foundation; either version 3, or (at your option) any
196       later version.
197
198       Math-PlanePath is distributed in the hope that it will be useful, but
199       WITHOUT ANY WARRANTY; without even the implied warranty of
200       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
201       General Public License for more details.
202
203       You should have received a copy of the GNU General Public License along
204       with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.
205
206
207
208perl v5.34.0                      2022-01-M2a1th::PlanePath::CornerAlternating(3)
Impressum