Math::...Octant(3pm)
hey bestie ๐ welcome to Math::...Octant(3pm) from User Contributed Perl Documentation ๐ okay so this is the math-plane-path girlies' corner of the internet and this particular one is lowkey gorgeous. geometry? slay. let's get into it ๐ฆ
โจ NAME โจ
Math::PlanePath::HypotOctant โ it's literally the octant of points, ordered by hypotenuse distance ๐ซ
๐ธ SYNOPSIS ๐ธ
use Math::PlanePath::HypotOctant;
my $path = Math::PlanePath::HypotOctant->new;
my ($x, $y) = $path->n_to_xy (123);
๐ DESCRIPTION ๐
okay so this path walks an octant of integer points X,Y and it visits them in order of how far they are from the origin 0,0 ๐ the points make a rising triangle where 0<=Y<=X, and it looks like this:
8 | 61
7 | 47 54
6 | 36 43 49
5 | 27 31 38 44
4 | 18 23 28 34 39
3 | 12 15 19 24 30 37
2 | 6 9 13 17 22 29 35
1 | 3 5 8 11 16 21 26 33
Y=0 | 1 2 4 7 10 14 20 25 32 ...
+---------------------------------------
X=0 1 2 3 4 5 6 7 8
like, for example, N=11 at X=4,Y=1 is sqrt(4*4+1*1) = sqrt(17) from the origin ๐งฎ and the next furthest away from the origin is X=3,Y=3 at sqrt(18). obsessed with the tidiness fr fr.
this octant is "primitive" elements X^2+Y^2 in the sense that it excludes negative X or Y or swapped Y,X ๐ (so it's the no-duplicates, no-negatives version, iykyk)
๐ฅ Equal Distances ๐ฅ
when points have the same distance from the origin, they get taken in anti-clockwise order starting from the X axis โ which, translation, means by increasing Y. and points only end up with the same distance when there's more than one way to write that distance as the sum of two squares ๐
Pythagorean triples hand you a point on the X axis and a point above it. for example 5^2 == 4^2 + 3^2 has N=14 at X=5,Y=0 which is just plain old 5^2 = 5^2 + 0, and then N=15 at X=4,Y=3 for the triple. both of them are 5 away from the origin. iconic behaviour honestly ๐
and combinations like 20^2 + 15^2 == 24^2 + 7^2 happen too ๐ญ and it can even go off with three or more different ways to land on the same sum distance. the math is mathing.
๐ฆ Even Points ๐ฆ
the option points => "even" visits just the even points, meaning the sum X+Y is even โ so X,Y are both even or both odd โจ
12 | 66
11 | points => "even" 57
10 | 49 58
9 | 40 50
8 | 32 41 51
7 | 25 34 43
6 | 20 27 35 45
5 | 15 21 29 37
4 | 10 16 22 30 39
3 | 7 11 17 24 33
2 | 4 8 13 19 28 38
1 | 2 5 9 14 23 31
Y=0 | 1 3 6 12 18 26 36
+---------------------------------------
X=0 1 2 3 4 5 6 7 8 9 10 11 12
the even points can be mapped onto all the points with a 45 degree rotate and flip, which is so cute. N=1,3,6,12,etc on the X axis here is on the X=Y diagonal of all-points. and conversely, N=1,2,4,7,10,etc on the X=Y diagonal here is on the X axis of all-points ๐ซ
all_X = (even_X + even_Y) / 2
all_Y = (even_X - even_Y) / 2
even_X = (all_X + all_Y)
even_Y = (all_X - all_Y)
the sets of points with equal hypotenuse are the same in the even version and the all version, but the flip takes them in reverse order ๐ the first such reversal shows up at N=14 and N=15. in even-points they're at 7,1 and 5,5. in all-points they're at 5,0 and 4,3, and those two map to 5,5 and 7,1 โ ie. the opposite way around. not me getting emotional over a coordinate flip ๐ญ
๐ Odd Points ๐
the option points => "odd" visits just the odd points, meaning the sum X+Y is odd โ so X,Y are one odd and the other even ๐
12 | 66
11 | points => "odd" 57
10 | 47 58
9 | 39 49
8 | 32 41 51
7 | 25 33 42
6 | 20 26 35 45
5 | 14 21 29 37
4 | 10 16 22 30 40
3 | 7 11 17 24 34
2 | 4 8 13 19 28 38
1 | 2 5 9 15 23 31
Y=0 | 1 3 6 12 18 27 36
+------------------------------------------
X=0 1 2 3 4 5 6 7 8 9 10 11 12 13
the X=Y diagonal gets excluded here because it has X+Y even ๐ sorry diagonal, not your era.
๐ FUNCTIONS ๐
peep "FUNCTIONS" in Math::PlanePath for the behaviour that's common to literally every path class, no cap.
$path = Math::PlanePath::HypotOctant->new ()$path = Math::PlanePath::HypotOctant->new (points => $str)โ make a new hypot octant path object and hand it back to you ๐ซถ thepointsoption can be:
"all" all integer X,Y (the default)
"even" only points with X+Y even
"odd" only points with X+Y odd
($x,$y) = $path->n_to_xy ($n)โ returns the X,Y coordinates of point number$non the path โจ- for
$n < 1you get back an empty list, because the first point at X=0,Y=0 is considered to be N=1 ๐ซ - right now it's unspecified what happens if
$nisn't an integer. the successive points are a fair way apart, so handing it an X,Y position in between the integer$nmight not make much sense ๐คทโโ๏ธ
- for
$n = $path->xy_to_n ($x,$y)โ returns an integer point number for the coordinates$x,$y. every integer N is treated as the centre of a unit square, and an$x,$ythat lands inside that square returns that N ๐ฏ
๐งฎ FORMULAS ๐งฎ
ngl the calculations are not very efficient currently ๐ for each Y row, a current X and the matching hypotenuse X^2+Y^2 are kept around. to find the next furthest, it searches through all those hypotenuses looking for the smallest โ including the equal smallest ones โ and those become the next N points โจ
for n_to_xy() an array gets built inside the object, and it's used for repeat calculations. for xy_to_n() an array of hypot to N gives you a the first N of a given X^2+Y^2 distance, and then a search runs through the next few N for the case where there's more than one X,Y at that hypot ๐
๐ OEIS ๐
entries in Sloane's Online Encyclopedia of Integer Sequences related to this path include:
<http://oeis.org/A024507> (etc)
points="all"
A024507 X^2+Y^2 of all points not on X axis or X=Y diagonal
A024509 X^2+Y^2 of all points not on X axis
being integers occurring as sum of two non-zero squares,
with repetitions for multiple ways
points="even"
A036702 N on X=Y leading Diagonal
being count of points norm<=k
points="odd"
A057653 X^2+Y^2 values occurring
ie. odd numbers which are sum of two squares,
without repetitions
๐ SEE ALSO ๐
Math::PlanePath, Math::PlanePath::Hypot, Math::PlanePath::TriangularHypot, Math::PlanePath::PixelRings, Math::PlanePath::PythagoreanTree โ the whole squad, go say hi ๐ซถ
๐ HOME PAGE ๐
<http://user42.tuxfamily.org/math-planepath/index.html>
๐ LICENSE ๐
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 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 do not skip the license part, it's the legal main character energy and it stays, periodt.
and that's a wrap! this lil number came from perl v5.32.0 dated 2021-01-23 โ shoutout to the Math::...Octant(3pm) page, you ate and left no crumbs ๐
โจ
๐ฆ where this page comes from
- debian bookworm: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- debian trixie: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu jammy: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu noble: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu resolute: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ubuntu stonking: libmath-planepath-perl 129-1 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms