NAME

Math::PlanePath::MathImageGrayCode -- Gray code coordinates

SYNOPSIS

use Math::PlanePath::MathImageGrayCode;

my $path = Math::PlanePath::MathImageGrayCode->new;
my ($x, $y) = $path->n_to_xy (123);

DESCRIPTION

In progress...

N

 7  |  63-62 57-56 39-38 33-32
    |      |  |        |  |   
 6  |  60-61 58-59 36-37 34-35
    |                         
 5  |  51-50 53-52 43-42 45-44
    |      |  |        |  |   
 4  |  48-49 54-55 40-41 46-47
    |                         
 3  |  15-14  9--8 23-22 17-16
    |      |  |        |  |   
 2  |  12-13 10-11 20-21 18-19
    |                         
 1  |   3--2  5--4 27-26 29-28
    |      |  |        |  |   
Y=0 |   0--1  6--7 24-25 30-31
    |
    +-------------------------
      X=0  1  2  3  4  5  6  7

XY

For the XY form the X and Y coordinates are Gray codes generated from N. Integer N is converted to its Gray code and that code is split by bits to give X and Y.

 7  |  51-50 52-53 44-45 43-42
    |      |     |     |     |
 6  |  48-49 55-54 47-46 40-41
    |                         
 5  |  60-61 59-58 35-34 36-37
    |      |     |     |     |
 4  |  63-62 56-57 32-33 39-38
    |                         
 3  |  12-13 11-10 19-18 20-21
    |      |     |     |     |
 2  |  15-14  8--9 16-17 23-22
    |                         
 1  |   3--2  4--5 28-29 27-26
    |      |     |     |     |
Y=0 |   0--1  7--6 31-30 24-25
    |  
    +-------------------------
      X=0  1  2  3  4  5  6  7

A change N to N+1 is a single bit change in its Gray code, and therefore a single bit change in one of X or Y. For example N=19 to N=20 is a change from X=4 to X=6, a single bit change. An increment can also turn off a bit, as for example N=23 to N=24 changes from Y=2 to Y=0.

Z_N

 7  | 34-35 39-38 55-54 50-51
    |   \     /     /     \  
 6  | 32-33 37-36 53-52 48-49
    |                        
 5  | 40-41 45-44 61-60 56-57
    |   /     \     \     /  
 4  | 42-43 47-46 63-62 58-59
    |                        
 3  |  8--9 13-12 29-28 24-25
    |   /     \     \     /  
 2  | 10-11 15-14 31-30 26-27
    |                        
 1  |  2--3  7--6 23-22 18-19
    |   \     /     /     \  
Y=0 |  0--1  5--4 21-20 16-17
    |
    +-------------------------
      X=0 1  2  3  4  5  6  7

Z_XY

 7  | 42-43 46-47 58-59 62-63
    |   \  \  \     \  \  \  
 6  | 40-41 44-45 56-57 60-61
    |                        
 5  | 34-35 38-39 50-51 54-55
    |   \  \  \     \  \  \  
 4  | 32-33 36-37 48-49 52-53
    |                        
 3  | 10-11 14-15 26-27 30-31
    |   \  \  \     \  \  \  
 2  |  8--9 12-13 24-25 28-29
    |                        
 1  |  2--3  6--7 18-19 22-23
    |   \  \  \     \  \  \  
Y=0 |  0--1  4--5 16-17 20-21
    |
    +-------------------------
      X=0 1  2  3  4  5  6  7

FUNCTIONS

See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes.

$path = Math::PlanePath::MathImageGrayCode->new ()

Create and return a new path object. The optional radix parameter gives the base for digit splitting (the default is binary, radix 2).

($x,$y) = $path->n_to_xy ($n)

Return the X,Y coordinates of point number $n on the path. Points begin at 0 and if $n < 0 then the return is an empty list.

SEE ALSO

Math::PlanePath, Math::PlanePath::ZOrderCurve