1Math::NumSeq::PlanePathUCsoeorrdC(o3n)tributed Perl DocuMmaetnht:a:tNiuomnSeq::PlanePathCoord(3)
2
3
4
6 Math::NumSeq::PlanePathCoord -- sequence of coordinate values from a
7 PlanePath module
8
10 use Math::NumSeq::PlanePathCoord;
11 my $seq = Math::NumSeq::PlanePathCoord->new
12 (planepath => 'SquareSpiral',
13 coordinate_type => 'X');
14 my ($i, $value) = $seq->next;
15
17 This is a tie-in to make a "NumSeq" sequence giving coordinate values
18 from a "Math::PlanePath". The NumSeq "i" index is the PlanePath "N"
19 value.
20
21 The "coordinate_type" choices are as follows. Generally they have some
22 sort of geometric interpretation or are related to fractions X/Y.
23
24 "X" X coordinate
25 "Y" Y coordinate
26 "Min" min(X,Y)
27 "Max" max(X,Y)
28 "MinAbs" min(abs(X),abs(Y))
29 "MaxAbs" max(abs(X),abs(Y))
30 "Sum" X+Y sum
31 "SumAbs" abs(X)+abs(Y) sum
32 "Product" X*Y product
33 "DiffXY" X-Y difference
34 "DiffYX" Y-X difference (negative of DiffXY)
35 "AbsDiff" abs(X-Y) difference
36 "Radius" sqrt(X^2+Y^2) radial distance
37 "RSquared" X^2+Y^2 radius squared (norm)
38 "TRadius" sqrt(X^2+3*Y^2) triangular radius
39 "TRSquared" X^2+3*Y^2 triangular radius squared (norm)
40 "IntXY" int(X/Y) division rounded towards zero
41 "FracXY" frac(X/Y) division rounded towards zero
42 "BitAnd" X bitand Y
43 "BitOr" X bitor Y
44 "BitXor" X bitxor Y
45 "GCD" greatest common divisor X,Y
46 "Depth" tree_n_to_depth()
47 "SubHeight" tree_n_to_subheight()
48 "NumChildren" tree_n_num_children()
49 "NumSiblings" not including self
50 "RootN" the N which is the tree root
51 "IsLeaf" 0 or 1 whether a leaf node (no children)
52 "IsNonLeaf" 0 or 1 whether a non-leaf node (has children)
53 also called an "internal" node
54
55 Min and Max
56 "Min" and "Max" are the minimum or maximum of X and Y. The geometric
57 interpretation of "Min" is to select X at any point above the X=Y
58 diagonal or Y for any point below. Conversely "Max" is Y above and X
59 below. On the X=Y diagonal itself X=Y=Min=Max.
60
61 Max=Y / X=Y diagonal
62 Min=X | /
63 |/
64 ---o----
65 /|
66 / | Max=X
67 / Min=Y
68
69 Min and Max can also be interpreted as counting which gnomon shaped
70 line the X,Y falls on.
71
72 | | | | Min=gnomon 2 ------------. Max=gnomon
73 | | | | 1 ----------. |
74 | | | | ... 0 --------o | |
75 | | | ------ 1 -1 ------. | | |
76 | | o-------- 0 ... | | | |
77 | ---------- -1 | | | |
78 ------------ -2 | | | |
79
80 MinAbs
81 MinAbs = min(abs(X),abs(Y)) can be interpreted geometrically as
82 counting gnomons successively away from the origin. This is like Min
83 above, but within the quadrant containing X,Y.
84
85 | | | | | MinAbs=gnomon counted away from the origin
86 | | | | |
87 2 --- | | | ---- 2
88 1 ----- | ------ 1
89 0 -------o-------- 0
90 1 ----- | ------ 1
91 2 --- | | | ---- 2
92 | | | | |
93 | | | | |
94
95 MaxAbs
96 MaxAbs = max(abs(X),abs(Y)) can be interpreted geometrically as
97 counting successive squares around the origin.
98
99 +-----------+ MaxAbs=which square
100 | +-------+ |
101 | | +---+ | |
102 | | | o | | |
103 | | +---+ | |
104 | +-------+ |
105 +-----------+
106
107 For example Math::PlanePath::SquareSpiral loops around in squares and
108 so its MaxAbs is unchanged until it steps out to the next bigger
109 square.
110
111 Sum and Diff
112 "Sum"=X+Y and "DiffXY"=X-Y can be interpreted geometrically as
113 coordinates on 45-degree diagonals. Sum is a measure up along the
114 leading diagonal and DiffXY down an anti-diagonal,
115
116 \ /
117 \ s=X+Y /
118 \ ^\
119 \ / \
120 \ | / v
121 \|/ * d=X-Y
122 ---o----
123 /|\
124 / | \
125 / | \
126 / \
127 / \
128 / \
129
130 Or "Sum" can be thought of as a count of which anti-diagonal stripe
131 contains X,Y, or a projection onto the X=Y leading diagonal.
132
133 Sum
134 \ = anti-diag
135 2 numbering / / / / DiffXY
136 \ \ X+Y -1 0 1 2 = diagonal
137 1 2 / / / / numbering
138 \ \ \ -1 0 1 2 X-Y
139 0 1 2 / / /
140 \ \ \ 0 1 2
141
142 DiffYX
143 "DiffYX" = Y-X is simply the negative of DiffXY. It's included to give
144 positive values on paths which are above the X=Y leading diagonal. For
145 example DiffXY is positive in "CoprimeColumns" which is below X=Y,
146 whereas DiffYX is positive in "CellularRule" which is above X=Y.
147
148 SumAbs
149 "SumAbs" = abs(X)+abs(Y) is similar to the projection described above
150 for Sum or Diff, but SumAbs projects onto the central diagonal of
151 whichever quadrant contains the X,Y. Or equivalently it's a numbering
152 of anti-diagonals within that quadrant, so numbering which diamond
153 shape the X,Y falls on.
154
155 |
156 /|\ SumAbs = which diamond X,Y falls on
157 / | \
158 / | \
159 -----o-----
160 \ | /
161 \ | /
162 \|/
163 |
164
165 As an example, the "DiamondSpiral" path loops around on such diamonds,
166 so its SumAbs is unchanged until completing a loop and stepping out to
167 the next bigger.
168
169 SumAbs is also a "taxi-cab" or "Manhattan" distance, being how far to
170 travel through a square-grid city to get to X,Y.
171
172 SumAbs = taxi-cab distance, by any square-grid travel
173
174 +-----o +--o o
175 | | |
176 | +--+ +-----+
177 | | |
178 * * *
179
180 If a path is entirely X>=0,Y>=0 in the first quadrant then Sum and
181 SumAbs are identical.
182
183 AbsDiff
184 "AbsDiff" = abs(X-Y) can be interpreted geometrically as the distance
185 away from the X=Y diagonal, measured at right-angles to that line.
186
187 d=abs(X-Y)
188 ^ / X=Y line
189 \ /
190 \/
191 /\
192 / \
193 |/ \
194 --o-- \
195 /| v
196 / d=abs(X-Y)
197
198 If a path is entirely below the X=Y line, so X>=Y, then AbsDiff is the
199 same as DiffXY. Or if a path is entirely above the X=Y line, so Y>=X,
200 then AbsDiff is the same as DiffYX.
201
202 Radius and RSquared
203 Radius and RSquared are per "$path->n_to_radius()" and
204 "$path->n_to_rsquared()" respectively (see "Coordinate Methods" in
205 Math::PlanePath).
206
207 TRadius and TRSquared
208 "TRadius" and "TRSquared" are designed for use with points on a
209 triangular lattice as per "Triangular Lattice" in Math::PlanePath. For
210 points on the X axis TRSquared is the same as RSquared but off the axis
211 Y is scaled up by factor sqrt(3).
212
213 Most triangular paths use "even" points X==Y mod 2 and for them
214 TRSquared is always even. Some triangular paths such as "KochPeaks"
215 have an offset from the origin and use "odd" points X!=Y mod 2 and for
216 them TRSquared is odd.
217
218 IntXY and FracXY
219 "IntXY" = int(X/Y) is the quotient from X divide Y rounded to an
220 integer towards zero. This is like the integer part of a fraction, for
221 example X=9,Y=4 is 9/4 = 2+1/4 so IntXY=2. Negatives are reckoned with
222 the fraction part negated too, so -2 1/4 is -2-1/4 and thus IntXY=-2.
223
224 Geometrically IntXY gives which wedge of slope 1, 2, 3, etc the point
225 X,Y falls in. For example IntXY is 3 for all points in the wedge
226 3Y<=X<4Y.
227
228 X=Y X=2Y X=3Y X=4Y
229 * -2 * -1 * 0 | 0 * 1 * 2 * 3 *
230 * * * | * * * *
231 * * * | * * * *
232 * * * | * * * *
233 * * * | * * * *
234 * * * | * * * *
235 ***|****
236 ---------------------+----------------------------
237 **|**
238 * * | * *
239 * * | * *
240 * * | * *
241 * * | * *
242 2 * 1 * 0 | 0 * -1 * -2
243
244 "FracXY" is the fraction part which goes with IntXY. In all cases
245
246 X/Y = IntXY + FracXY
247
248 IntXY rounds towards zero so the remaining FracXY has the same sign as
249 IntXY.
250
251 BitAnd, BitOr, BitXor
252 "BitAnd", "BitOr" and "BitXor" treat negative X or negative Y as
253 infinite twos-complement 1-bits, which means for example X=-1,Y=-2 has
254 X bitand Y = -2.
255
256 ...11111111 X=-1
257 ...11111110 Y=-2
258 -----------
259 ...11111110 X bitand Y = -2
260
261 This twos-complement is per "Math::BigInt" (which has bitwise
262 operations in Perl 5.6 and up). The code here arranges the same on
263 ordinary scalars.
264
265 If X or Y are not integers then the fractional parts are treated
266 bitwise too, but currently only to limited precision.
267
269 See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
270 classes.
271
272 "$seq = Math::NumSeq::PlanePathCoord->new (planepath => $name,
273 coordinate_type => $str)"
274 Create and return a new sequence object. The options are
275
276 planepath string, name of a PlanePath module
277 planepath_object PlanePath object
278 coordinate_type string, as described above
279
280 "planepath" can be either the module part such as "SquareSpiral" or
281 a full class name "Math::PlanePath::SquareSpiral".
282
283 "$value = $seq->ith($i)"
284 Return the coordinate at N=$i in the PlanePath.
285
286 "$i = $seq->i_start()"
287 Return the first index $i in the sequence. This is the position
288 rewind() returns to.
289
290 This is "$path->n_start()" from the PlanePath, since the i
291 numbering is the N numbering of the underlying path. For some of
292 the "Math::NumSeq::OEIS" generated sequences there may be a higher
293 i_start() corresponding to a higher starting point in the OEIS,
294 though this is slightly experimental.
295
296 "$str = $seq->oeis_anum()"
297 Return the A-number (a string) for $seq in Sloane's Online
298 Encyclopedia of Integer Sequences, or return "undef" if not in the
299 OEIS or not known.
300
301 Known A-numbers are also presented through
302 "Math::NumSeq::OEIS::Catalogue". This means PlanePath related OEIS
303 sequences can be created with "Math::NumSeq::OEIS" by giving their
304 A-number in the usual way for that module.
305
307 Math::NumSeq, Math::NumSeq::PlanePathDelta,
308 Math::NumSeq::PlanePathTurn, Math::NumSeq::PlanePathN,
309 Math::NumSeq::OEIS
310
311 Math::PlanePath
312
314 <http://user42.tuxfamily.org/math-planepath/index.html>
315
317 Copyright 2011, 2012, 2013, 2014 Kevin Ryde
318
319 This file is part of Math-PlanePath.
320
321 Math-PlanePath is free software; you can redistribute it and/or modify
322 it under the terms of the GNU General Public License as published by
323 the Free Software Foundation; either version 3, or (at your option) any
324 later version.
325
326 Math-PlanePath is distributed in the hope that it will be useful, but
327 WITHOUT ANY WARRANTY; without even the implied warranty of
328 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
329 General Public License for more details.
330
331 You should have received a copy of the GNU General Public License along
332 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
333
334
335
336perl v5.38.0 2023-07-20 Math::NumSeq::PlanePathCoord(3)