++ed by:
Kevin Ryde
and 1 contributors

# NAME

Math::PlanePath::Diagonals -- points in diagonal stripes

# SYNOPSIS

`````` use Math::PlanePath::Diagonals;
my \$path = Math::PlanePath::Diagonals->new;
my (\$x, \$y) = \$path->n_to_xy (123);``````

# DESCRIPTION

This path follows successive diagonals going from the Y axis down to the X axis.

``````    ...
6  |  22
5  |  16  23
4  |  11  17  ...
3  |   7  12  18  ...
2  |   4   8  13  19  ...
1  |   2   5   9  14  20  ...
y=0  |   1   3   6  10  15  21  ...
--------------------------
x=0,  1   2   3   4 ...``````

The horizontal sequence 1,3,6,10,etc at y=0 is the triangular numbers s*(s+1)/2. If you plot them on a graph don't confuse that line with the axis or border!

# FUNCTIONS

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

`\$path = Math::PlanePath::Diagonals->new ()`

Create and return a new path object.

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

Return the X,Y coordinates of point number `\$n` on the path.

For `\$n < 0.5` the return is an empty list, it being considered the path begins at 1.

`\$n = \$path->xy_to_n (\$x,\$y)`

Return the point number for coordinates `\$x,\$y`. `\$x` and `\$y` are each rounded to the nearest integer, which has the effect of treating each point `\$n` as a square of side 1, so the quadrant x>=-0.5, y>=-0.5 is entirely covered.

# FORMULAS

## Rectangle to N Range

Within each row increasing X is increasing N, and in each column increasing Y is increasing N. On that basis in a rectangle the lower left corner is the minimum N and the upper right is the maximum N.

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