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
"dAbsDiff"  change in abs(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 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

"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 and dDiffYX

"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.

dAbsDiff

"dAbsDiff" is the change in AbsDiff = abs(X-Y). AbsDiff can be interpreted geometrically as distance from the leading diagonal, as described in "AbsDiff" in Math::NumSeq::PlanePathCoord. dAbsDiff is therefore movement closer to or further away from the leading diagonal, measured perpendicular to it.

        / X=Y line
       /
      /  ^
     /    \
    /      *  dAbsDiff towards or away from X=Y line
  |/        \
--o--        v
 /|
/

Dir4

"Dir4" direction is a direction angle scaled to make a circle range from 0 to 4. The cardinal directions N,S,E,W are therefore 0,1,2,3. Angles in between are a fraction.

Dir4 = atan2 (dY, dX)       in range to 0 <= Dir4 < 4

1.5   1   0.5
    \ | /
     \|/
2 ----o---- 0
     /|\
    / | \
2.5   3   3.5

TDir6

"TDir6" is a direction in triangular style per "Triangular Lattice" in Math::PlanePath. So dX=1,dY=1 is 60 degrees and scaled to range 0 to 6 gives 1. Angles in between the six cardinal directions are fractions.

   2       1
     \   /                  north=1.5
      \|/                   south=4.5
3 -----o----- 0
      /|\
     /   \
   4       5

The angle is calculated as if dY was scaled by a factor sqrt(3) to make the lattice into equilateral triangles, or equivalently as a circle stretched to be an ellipse.

TDir6 = atan2(dY*sqrt(3), dX)      in range 0 <= TDir6 < 6

Notice that angles dX=0 or dY=0 on the axes are unchanged except for the scaling range 0 to 6. For example West is 180/360*6=3. Verticals north and south normally doesn't occur in the triangular style paths, but if they do or if TDir6 is applied to other paths, then north is 90/360*6=1.5 and south is 270/360*6=4.5, in between the 1,2 or 4,5 diagonals.

The sqrt(3) factor increases angles in the middle of a quadrant. For example dX=1,dY=1 becomes TDir6=1 whereas a plain angle would be only 45/360*6=0.75 in the same 0 to 6 range. The sqrt(3) is a continuous scaling, so a plain angle and a TDir6 are a one-to-one mapping. The TDir6 grows a bit faster then a bit slower as the direction progresses through the quadrant.

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

Math::PlanePath

HOME PAGE

http://user42.tuxfamily.org/math-planepath/index.html

LICENSE

Copyright 2011, 2012, 2013 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/>.