NAME
Math::NumSeq::PlanePathDelta -- sequence of changes and directions of PlanePath coordinates
SYNOPSIS
use Math::NumSeq::PlanePathDelta;
my $seq = Math::NumSeq::PlanePathDelta->new
(planepath => 'SquareSpiral',
delta_type => 'dX');
my ($i, $value) = $seq->next;
DESCRIPTION
This is a tie-in to present coordinate changes and directions from a Math::PlanePath
module in the form of a NumSeq sequence.
The delta_type
choices are
"dX" change in X coordinate
"dY" change in Y coordinate
"AbsdX" abs(dX)
"AbsdY" abs(dY)
"dSum" change in X+Y, equals dX+dY
"dDiffXY" change in X-Y, equals dX-dY
"dDiffYX" change in Y-X, equals dY-dX
"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 per $path->n_to_dxdy($i)
, being the change from N=i to N=i+1, 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()
.
"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 counts anti-diagonals, as described in Math::NumSeq::PlanePathCoord. dSum is therefore a move 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 counts diagonals downwards to the south-east as described in Math::NumSeq::PlanePathCoord. dDiffXY is therefore movement between those diagonals, or 0 if a step stays within the same diagonal.
"dDiffYX" is the negative of dDiffXY. Whether X-Y or Y-X is desired depends on which way you want to measure diagonals, or what sign to have for the changes. dDiffYX is based on Y-X and so counts diagonals upwards to the North-West.
"Dir4" direction is a fraction when a delta is in between the cardinal N,S,E,W directions. For example dX=-1,dY=+1 going diagonally North-West would be direction=1.5.
Dir4 = atan2 (dY, dX) in range to 0 <= Dir4 < 4
"TDir6" direction is in triangular style per "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 if in between. It behaves as if dY was scaled by a factor sqrt(3) to make equilateral triangles,
TDir6 = atan2(dY*sqrt(3), dX) in range 0 <= TDir6 < 6
FUNCTIONS
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". $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.This is
$path->n_start()
from the PlanePath.
SEE ALSO
Math::NumSeq, Math::NumSeq::PlanePathCoord, Math::NumSeq::PlanePathTurn, Math::NumSeq::PlanePathN
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/>.