Math::...hCoord(3pm)

πŸ“¦
version 129 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸŽ€ NAME πŸŽ€

Math::NumSeq::PlanePathCoord β€” bestie that's the manual name right there, and what it is is a sequence of coordinate values from a PlanePath module. ✨

This is the Math::NumSeq::PlanePathCoord(3pm) page from the User Contributed Perl Documentation, and we are going through every single line of it, no skipping, no skimming, we are eating the whole thing. πŸ’…


✨ SYNOPSIS ✨

use Math::NumSeq::PlanePathCoord;
my $seq = Math::NumSeq::PlanePathCoord->new
            (planepath => 'SquareSpiral',
             coordinate_type => 'X');
my ($i, $value) = $seq->next;

that's literally the whole summoning ritual 🫢


🌸 DESCRIPTION 🌸

okay so the vibe here is that this module is a tie-in β€” a little collab, if you will πŸ’– β€” that makes a NumSeq sequence handing you coordinate values from a Math::PlanePath. And the mapping is the cutest part: the NumSeq i index is the PlanePath N value. Same number, same energy, no conversion needed. 😌

The coordinate_type choices are as follows, and generally they have some sort of geometric interpretation or are related to fractions X/Y. Here is every single one of them, no cap:

  • "X" β€” the X coordinate, obviously πŸ’…
  • "Y" β€” the Y coordinate
  • "Min" β€” min(X,Y)
  • "Max" β€” max(X,Y)
  • "MinAbs" β€” min(abs(X),abs(Y))
  • "MaxAbs" β€” max(abs(X),abs(Y))
  • "Sum" β€” X+Y sum
  • "SumAbs" β€” abs(X)+abs(Y) sum
  • "Product" β€” X*Y product
  • "DiffXY" β€” X-Y difference
  • "DiffYX" β€” Y-X difference (negative of DiffXY)
  • "AbsDiff" β€” abs(X-Y) difference
  • "Radius" β€” sqrt(X^2+Y^2) radial distance
  • "RSquared" β€” X^2+Y^2 radius squared (norm)
  • "TRadius" β€” sqrt(X^2+3*Y^2) triangular radius
  • "TRSquared" β€” X^2+3*Y^2 triangular radius squared (norm)
  • "IntXY" β€” int(X/Y) division rounded towards zero
  • "FracXY" β€” frac(X/Y) division rounded towards zero
  • "BitAnd" β€” X bitand Y
  • "BitOr" β€” X bitor Y
  • "BitXor" β€” X bitxor Y
  • "GCD" β€” greatest common divisor X,Y
  • "Depth" β€” tree_n_to_depth()
  • "SubHeight" β€” tree_n_to_subheight()
  • "NumChildren" β€” tree_n_num_children()
  • "NumSiblings" β€” not including self
  • "RootN" β€” the N which is the tree root
  • "IsLeaf" β€” 0 or 1 whether a leaf node (no children)
  • "IsNonLeaf" β€” 0 or 1 whether a non-leaf node (has children), also called an "internal" node

πŸ¦‹ Min and Max πŸ¦‹

"Min" and "Max" are the minimum or maximum of X and Y. The geometric read on "Min" is that it selects X at any point above the X=Y diagonal, or Y for any point below. And "Max" is the opposite twin: Y above, X below. On the X=Y diagonal itself, X=Y=Min=Max β€” they're all the same, main character energy. ✨

           Max=Y      / X=Y diagonal
           Min=X   | /
                   |/
                ---o----
                  /|
                 / |     Max=X
                /        Min=Y

Min and Max can also be interpreted as counting which gnomon shaped line the X,Y falls on. 🌈

           | | | |     Min=gnomon           2 ------------.  Max=gnomon
           | | | |                          1 ----------. |
           | | | |      ...                 0 --------o | |
           | | |  ------ 1                 -1 ------. | | |
           | | o-------- 0                 ...      | | | |
           |  ---------- -1                         | | | |
            ------------ -2                         | | | |

πŸŽ€ MinAbs πŸŽ€

MinAbs = min(abs(X),abs(Y)) and you can interpret it geometrically as counting gnomons successively away from the origin. It's like Min above, but within the quadrant containing X,Y. πŸ’–

                | | | | |          MinAbs=gnomon counted away from the origin
                | | | | |
           2 ---  | | |  ---- 2
           1 -----  |  ------ 1
           0 -------o-------- 0
           1 -----  |  ------ 1
           2 ---  | | |  ---- 2
                | | | | |
                | | | | |

πŸ’œ MaxAbs πŸ’œ

MaxAbs = max(abs(X),abs(Y)) and it's geometrically counting successive squares around the origin. It's giving concentric-rings realness. 🫢

           +-----------+       MaxAbs=which square
           | +-------+ |
           | | +---+ | |
           | | | o | | |
           | | +---+ | |
           | +-------+ |
           +-----------+

For example Math::PlanePath::SquareSpiral loops around in squares and so its MaxAbs is unchanged until it steps out to the next bigger square. Obsessed with the consistency, honestly. 😌

🌈 Sum and Diff 🌈

"Sum"=X+Y and "DiffXY"=X-Y, and these can be interpreted geometrically as coordinates on 45-degree diagonals. Sum is a measure up along the leading diagonal and DiffXY down an anti-diagonal:

           \           /
            \   s=X+Y /
             \       ^\
              \     /  \
               \ | /    v
                \|/      * d=X-Y
              ---o----
                /|\
               / | \
              /  |  \
             /       \
            /         \
           /           \

Or "Sum" can be thought of as a count of which anti-diagonal stripe contains X,Y, or a projection onto the X=Y leading diagonal. ✨

                  Sum
           \     = anti-diag
            2      numbering          / / / /   DiffXY
           \ \       X+Y            -1 0 1 2   = diagonal
            1 2                     / / / /      numbering
           \ \ \                  -1 0 1 2         X-Y
            0 1 2                   / / /
             \ \ \                 0 1 2

πŸ“ DiffYX πŸ“

"DiffYX" = Y-X is simply the negative of DiffXY. It's included to give positive values on paths which are above the X=Y leading diagonal. For example DiffXY is positive in "CoprimeColumns" which is below X=Y, whereas DiffYX is positive in "CellularRule" which is above X=Y. See how they complement each other? it's giving balance. ⭐

🌸 SumAbs 🌸

"SumAbs" = abs(X)+abs(Y) and it's similar to the projection described above for Sum or Diff, except SumAbs projects onto the central diagonal of whichever quadrant contains the X,Y. Or equivalently it's a numbering of anti-diagonals within that quadrant, so numbering which diamond shape the X,Y falls on. πŸ’Ž

                |
               /|\       SumAbs = which diamond X,Y falls on
              / | \
             /  |  \
           -----o-----
             \  |  /
              \ | /
               \|/
                |

As an example, the "DiamondSpiral" path loops around on such diamonds, so its SumAbs is unchanged until completing a loop and stepping out to the next bigger. So consistent, so iconic. πŸ‘‘

SumAbs is also a "taxi-cab" or "Manhattan" distance β€” being how far you'd travel through a square-grid city to get to X,Y. πŸš•

           SumAbs = taxi-cab distance, by any square-grid travel

           +-----o       +--o          o
           |             |             |
           |          +--+       +-----+
           |          |          |
           *          *          *

And lowkey the best shortcut ever: if a path is entirely X>=0,Y>=0 in the first quadrant, then Sum and SumAbs are identical. Same number, two names, no notes. πŸ’…

πŸ¦‹ AbsDiff πŸ¦‹

"AbsDiff" = abs(X-Y) and you can interpret it geometrically as the distance away from the X=Y diagonal, measured at right-angles to that line.

            d=abs(X-Y)
                  ^    / X=Y line
                   \  /
                    \/
                    /\
                   /  \
                 |/    \
               --o--    \
                /|       v
               /           d=abs(X-Y)

If a path is entirely below the X=Y line, so X>=Y, then AbsDiff is the same as DiffXY. Or if a path is entirely above the X=Y line, so Y>=X, then AbsDiff is the same as DiffYX. See, everything connects. 🫢

πŸŽ€ Radius and RSquared πŸŽ€

Radius and RSquared are per $path->n_to_radius() and $path->n_to_rsquared() respectively (see "Coordinate Methods" in Math::PlanePath). that's the whole entry, bestie, go read that one too πŸ’–

πŸ’œ TRadius and TRSquared πŸ’œ

"TRadius" and "TRSquared" are designed for use with points on a triangular lattice as per "Triangular Lattice" in Math::PlanePath. For points on the X axis TRSquared is the same as RSquared but off the axis Y is scaled up by factor sqrt(3).

Most triangular paths use "even" points X==Y mod 2 and for them TRSquared is always even. Some triangular paths such as "KochPeaks" have an offset from the origin and use "odd" points X!=Y mod 2 and for them TRSquared is odd. parity lore fr fr 🌈

✨ IntXY and FracXY ✨

"IntXY" = int(X/Y) is the quotient from X divide Y rounded to an integer towards zero. This is like the integer part of a fraction, for example X=9,Y=4 is 9/4 = 2+1/4 so IntXY=2. Negatives are reckoned with the fraction part negated too, so -2 1/4 is -2-1/4 and thus IntXY=-2. πŸ’…

Geometrically IntXY gives which wedge of slope 1, 2, 3, etc the point X,Y falls in. For example IntXY is 3 for all points in the wedge 3Y<=X<4Y.

                                      X=Y    X=2Y   X=3Y   X=4Y
           *  -2  *  -1  *   0  |  0   *  1   *  2   *   3  *
              *     *     *     |     *     *     *     *
                 *    *    *    |    *    *    *    *
                    *   *   *   |   *   *   *   *
                       *  *  *  |  *  *  *  *
                          * * * | * * * *
                             ***|****
           ---------------------+----------------------------
                              **|**
                            * * | * *
                          *  *  |  *  *
                        *   *   |   *   *
                      *    *    |    *    *
                2   *  1  *  0  |  0  * -1  *  -2

"FracXY" is the fraction part which goes with IntXY. In all cases:

X/Y = IntXY + FracXY

IntXY rounds towards zero so the remaining FracXY has the same sign as IntXY. they stay matching, that's the rule πŸŽ€

🌸 BitAnd, BitOr, BitXor 🌸

"BitAnd", "BitOr" and "BitXor" treat negative X or negative Y as infinite twos-complement 1-bits, which means for example X=-1,Y=-2 has X bitand Y = -2.

...11111111    X=-1
...11111110    Y=-2
-----------
...11111110    X bitand Y = -2

This twos-complement is per "Math::BigInt" (which has bitwise operations in Perl 5.6 and up). The code here arranges the same on ordinary scalars. 😌

heads up bestie: if X or Y are not integers then the fractional parts are treated bitwise too, but currently only to limited precision. so don't come for it, it's doing its best πŸ’€

πŸ”₯ FUNCTIONS πŸ”₯

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

  • $seq = Math::NumSeq::PlanePathCoord->new (planepath => $name, coordinate_type => $str) β€” creates and returns a new sequence object. πŸ’–

The options are:

  • planepath β€” string, name of a PlanePath module
  • planepath_object β€” PlanePath object
  • coordinate_type β€” string, as described above

"planepath" can be either the module part such as "SquareSpiral" or a full class name "Math::PlanePath::SquareSpiral". either one, she's flexible 🫢

  • $value = $seq->ith($i) β€” return the coordinate at N=$i in the PlanePath.
  • $i = $seq->i_start() β€” return the first index $i in the sequence. This is the position "rewind()" returns to.

This is "$path->n_start()" from the PlanePath, since the i numbering is the N numbering of the underlying path. For some of the "Math::NumSeq::OEIS" generated sequences there may be a higher "i_start()" corresponding to a higher starting point in the OEIS, though this is slightly experimental. πŸ§ͺ

  • $str = $seq->oeis_anum() β€” return the A-number (a string) for $seq in Sloane's Online Encyclopedia of Integer Sequences, or return "undef" if not in the OEIS or not known.

Known A-numbers are also presented through "Math::NumSeq::OEIS::Catalogue". This means PlanePath related OEIS sequences can be created with "Math::NumSeq::OEIS" by giving their A-number in the usual way for that module. ✨

πŸ’– SEE ALSO πŸ’–

okay bestie, if you're done here and you want MORE, the whole little universe of related modules is right there:

  • Math::NumSeq
  • Math::NumSeq::PlanePathDelta
  • Math::NumSeq::PlanePathTurn
  • Math::NumSeq::PlanePathN
  • Math::NumSeq::OEIS
  • Math::PlanePath β€” yeah this one's the mothership, obviously πŸ’…

🌈 HOME PAGE 🌈

the whole vibe lives at <http://user42.tuxfamily.org/math-planepath/index.html> β€” go peek, it's giving official 🫢


πŸ‘‘ LICENSE πŸ‘‘

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

bestie listen β€” the ALL CAPS warranty bit is not me being dramatic, that's literally the legal text. NO WARRANTY. fr fr. 🫢

so that's the whole page, bestie, we made it to the end and honestly? iconic. this was perl v5.32.0, dated 2021-01-23, and it's the Math::...hCoord(3pm) page signing off. go plot some coordinates, you absolute legend πŸ’œπŸ¦‹βœ¨