NAME
Math::NumSeq::PlanePathCoord -- sequence of coordinate values from a PlanePath module
SYNOPSIS
use Math::NumSeq::PlanePathCoord;
my $seq = Math::NumSeq::PlanePathCoord->new
(planepath => 'SquareSpiral',
coordinate_type => 'X');
my ($i, $value) = $seq->next;
DESCRIPTION
This is a tie-in to present coordinates from a Math::PlanePath
module as a NumSeq sequence. The NumSeq "i" index is the PlanePath "N" value.
The coordinate_type
choices are
"X" X coordinate
"Y" Y coordinate
"Sum" X+Y sum
"SumAbs" abs(X)+abs(Y) sum
"Product" X*Y product
"DiffXY" X-Y difference
"DiffYX" Y-X difference (negative of DiffXY)
"AbsDiff" abs(X-Y) difference
"Radius" sqrt(X^2+Y^2) radial distance
"RSquared" X^2+Y^2 radius squared
"TRadius" sqrt(X^2+3*Y^2) triangular radius
"TRSquared" X^2+3*Y^2 triangular radius squared
"BitAnd" X bitand Y
"BitOr" X bitor Y
"BitXor" X bitxor Y
"Min" min(X,Y)
"Max" max(X,Y)
"GCD" greatest common divisor X,Y
"Depth" tree_n_to_depth()
"NumChildren" tree_n_num_children()
"Sum"=X+Y and "DiffXY=X-Y can be interpreted geometrically as coordinates on 45-degree diagonals. Sum is a measure up along the leading diagonal and DiffXY down along an anti-diagonal,
/
\ /
\ s=X+Y /
\ ^\
\ / \
\ | / v
\|/ * d=X-Y
---o----
/|\
/ | \
/ | \
/ \
/ \
/ \
Or "Sum" can be thought of as a count of which anti-diagonal stripe contains X,Y or equivalently a projection onto the X=Y leading diagonal.
Sum
\ anti-diag
2 numbering / / / / DiffXY
\ \ X+Y -1 0 1 2 diagonal
1 2 / / / / numbering
\ \ \ -1 0 1 2 X-Y
0 1 2 / / /
\ \ \ 0 1 2
"SumAbs"=abs(X)+abs(Y) is similar, but a projection onto the cross-diagonal of whichever quadrant contains the X,Y. It's also thought of as a "taxi-cab" or Manhatten distance, being how far to travel through a square-grid city to get to X,Y. If a path uses only the first quadrant, so X>=0,Y>=0, then of course Sum and SumAbs are identical.
SumAbs = taxi-cab distance, by any square-grid travel
+-----o +--o o
| | |
| +--+ +-----+
| | |
* * *
"DiffYX"=Y-X is simply the negative of DiffXY. It's included to give positive values on paths which are either above or below the X=Y leading diagonal. For example DiffXY is positive in CoprimeColumns which is below X=Y, whereas DiffYX is positive in CellularRule which is above X=Y.
"TRadius" and "TRSquared" are designed for use with points on a triangular lattice such as HexSpiral. On the X axis TRSquared is the same as RSquared, but any Y is scaled up by factor sqrt(3). Most triangular paths use every second X,Y point which makes TRSquared even, but some such as KochPeaks have an offset 1 from the origin making it odd instead.
"BitAnd", "BitOr" and "BitXor" treat negative X or negative Y as infinite twos-complement 1-bits, which means for example X=-1,Y=-2 has X bitand Y = -2.
...11111111 X=-1
...11111110 Y=-2
-----------
...11111110 X bitand Y = -2
This twos-complement is per Math::BigInt
(it has bitwise operations in Perl 5.6 and up) and is arranged for ordinary scalars too. If X or Y are not integers then the fractional parts are treated bitwise too, though currently only to limited precision.
FUNCTIONS
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::PlanePathCoord->new (planepath => $name, coordinate_type => 'X')
-
Create and return a new sequence object. The options are
planepath string, name of a PlanePath module planepath_object PlanePath object coordinate_type string, as described above
planepath
can be either the module part such as "SquareSpiral" or a full class name "Math::PlanePath::SquareSpiral". $value = $seq->ith($i)
-
Return the coordinate at N=$i in the PlanePath.
$i = $seq->i_start()
-
Return the first index
$i
in the sequence. This is the positionrewind()
returns to.This is
$path->n_start()
from the PlanePath, since the i numbering is the N numbering of the underlying path. For some of theMath::NumSeq::OEIS
generated sequences there may be a higheri_start()
corresponding to a higher starting point in the OEIS, though this is slightly experimental. $str = $seq->oeis_anum()
-
Return the A-number (a string) for
$seq
in Sloane's Online Encyclopedia of Integer Sequences, or returnundef
if not in the OEIS or not known.Known A-numbers are presented through
Math::NumSeq::OEIS::Catalogue
so PlanePath related sequences can be created withMath::NumSeq::OEIS
by their A-number in the usual way.
SEE ALSO
Math::NumSeq, Math::NumSeq::PlanePathDelta, Math::NumSeq::PlanePathTurn, Math::NumSeq::PlanePathN, Math::NumSeq::OEIS
HOME PAGE
http://user42.tuxfamily.org/math-planepath/index.html
LICENSE
Copyright 2011, 2012 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/>.