Math::NumSeq::PlanePathDelta -- sequence of changes and directions of PlanePath coordinates
use Math::NumSeq::PlanePathDelta; my $seq = Math::NumSeq::PlanePathDelta->new (planepath => 'SquareSpiral', delta_type => 'dX'); my ($i, $value) = $seq->next;
This is a tie-in to present coordinate changes and directions from a Math::PlanePath module in the form of a NumSeq sequence.
Math::PlanePath
The delta_type choices are
delta_type
"dX" change in X coordinate "dY" change in Y coordinate "dSum" change in X+Y "dDiffXY" change in X-Y "Dir4" direction 0=East, 1=North, 2=West, 3=South "TDir6" triangular 0=E, 1=NE, 2=NW, 3=W, 4=SW, 5=SE
In each case the value at i is the change from N=i to N=i+1 on the path, or from N=i to N=i+arms for paths with multiple "arms" (thus following a particular arm). i values start from the usual $path->n_start().
$path->n_start()
"dSum" is the change in X+Y and is also simply dX+dY, since
dSum = (Xnext+Ynext) - (X+Y) = (Xnext-X) + (Ynext-Y) = dX + dY
The sum X+Y numbers anti-diagonals (as described in Math::NumSeq::PlanePathCoord). dSum is therefore movement between diagonals, or 0 if a step stays within the same diagonal.
"dDiffXY" is the change in DiffXY = X-Y and is also simply dX-dY, since
dDiffXY = (Xnext-Ynext) - (X-Y) = (Xnext-X) - (Ynext-Y) = dX - dY
The difference X-Y numbers diagonals, downwards, as described in Math::NumSeq::PlanePathCoord. dDiffXY is therefore movement between those diagonals, or 0 if a step stays within the same diagonal.
"Dir4" is a fraction when a delta is in between the cardinal directions. For example dX=-1,dY=+1 going North-West would be direction 1.5.
Dir4 = atan2(dY, dX) in range to 0<=Dir4<4
"TDir6" is in the style of "Triangular Lattice" in Math::PlanePath. So dX=1,dY=1 is 60 degrees, dX=-1,dY=1 is 120 degrees, dX=-2,dY=0 is 180 degrees, etc and fractional values in between those. It behaves as if dY was scaled by a factor sqrt(3),
TDir6 = atan2(dY*sqrt(3), dX) in range 0<=TDir6<6
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::PlanePathDelta->new (key=>value,...)
Create and return a new sequence object. The options are
planepath string, name of a PlanePath module planepath_object PlanePath object delta_type string, as described above
planepath can be either the module part such as "SquareSpiral" or a full class name "Math::PlanePath::SquareSpiral".
planepath
$value = $seq->ith($i)
Return the change at N=$i in the PlanePath.
$i = $seq->i_start()
Return the first index $i in the sequence. This is the position $seq->rewind() returns to.
$i
$seq->rewind()
This is $path->n_start() from the PlanePath.
Math::NumSeq, Math::NumSeq::PlanePathCoord, Math::NumSeq::PlanePathTurn, Math::NumSeq::PlanePathN
http://user42.tuxfamily.org/math-planepath/index.html
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/>.
To install Math::PlanePath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::PlanePath
CPAN shell
perl -MCPAN -e shell install Math::PlanePath
For more information on module installation, please visit the detailed CPAN module installation guide.