Astro:...thUtils(3pm)
π NAME π
Astro::Montenbruck::Core::MathUtils β the core mathematical routines that all the Astro::Montenbruck modules lean on. The whole math brain trust, basically. This is page Astro:...thUtils(3pm), from the User Contributed Perl Documentation collection β¨
πΈ VERSION πΈ
Version 0.01 β baby version, but she works π
π¦ SYNOPSIS π¦
use Astro::Montenbruck::Core::MathUtils qw/dms/;
my ($d, $m, $s) = dms(55.75); # (55, 45, 0)
...
Like, that's it. That's the whole vibe. You pull in dms, you throw it a decimal, you get back a tidy little (55, 45, 0) trio π
β¨ EXPORT β¨
Here's the full squad of functions this module hands out. Yes, some of them are listed more than once β that's just how the source says it, so we're keeping it exactly the same, no edits, periodt π
frac($x)frac360($x)dms($x)hms($x)zdms($x)ddd($deg[, $min[, $sec]])polynome($t, @terms)to_range($x, $range)reduce_deg($x)reduce_rad($x)opposite_deg($x)opposite_rad($x)angle_c($x, $y)angle_c_rad($x, $y)angle_c_rad($x, $y)angle_s($x1, $y1, $x2, $y2)diff_angle($a, $b, $mode='degrees')diff_angle($a, $b, $mode='degrees')cart($r, $theta, $phi)polar($x, $y, $z)
π₯ SUBROUTINES π₯
π frac($x)
Gives you the fractional part of a decimal number. The little decimal crumbs at the end of the number, she isolates them. Obsessed π«Ά
π frac360($x)
A range function, similar to to_range($x, $range) β it's the one used together with the polynomial function so you get better accuracy. Teamwork makes the dream work β¨
π dms($x)
Okay so you give this one decimal hours (or degrees) and it hands back the nearest hours (or degrees) as an int, minutes as an int, and seconds as a float. Sexagesimal-era glow-up π«
Positional arguments:
- decimal value,
0..360for angular mode,0..24for time
Named arguments:
places(optional) β how many sexagesimal values you actually want returned (1-3); default =3(degrees/hours, minutes, seconds)
Returns:
- array of degrees (int), minutes (int), seconds (float)
π hms($x)
Just an alias for dms. Same function, different name, main character energy either way π
π zdms($x)
Takes decimal degrees and converts them into zodiac sign number (zero based), zodiac degrees, minutes and seconds. Astrology girlies stay winning π
Positional arguments:
- decimal value,
0..360for angular mode,0..24for time
Returns:
- array of zodiac sign (
0-11), degrees (int), minutes (int), seconds (float)
π ddd($deg[, $min[, $sec]])
The glow-down β converts sexagesimal values back to decimal. Reverse card, uno π΄
Arguments
1 to 3 sexagesimal values, like: degrees, minutes and seconds, or degrees and minutes, or literally just degrees:
ddd(11)ddd(11, 46)ddd(11, 46, 20)
If any non-zero argument is negative, the result is negative. Fr fr:
ddd(-11, 46, 0) = -11.766666666666667ddd(11, -46, 0) = 11.766666666666667
Negative sign in the wrong position is ignored. She just ignores it. No note, no error, just vibes π
Returns:
- decimal (degrees or hours)
π polynome($t, @terms)
Calculates the polynome: $a1 + $a2*$t + $a3*$t*$t + $a4*$t*$t*$t... β like, all the way down the line π
Arguments
$tcoefficient, in astronomical routines usually time in centuries- any number of decimal values
Returns:
- decimal number
π to_range($x, $range)
Reduces $x to 0 >= $x < $range. Keeping it in the box, respectfully π
Arguments
- number to reduce
- limit (non-inclusive), e.g:
360for degrees,24for hours
Returns
- number
π reduce_deg($x)
Reduces $x to 0 >= $x < 360
π reduce_rad($x)
Reduces $x to 0 >= $x < pi2
π opposite_deg($x)
Returns opposite degree. The 180Β° twin, if you will πͺ
π opposite_rad($x)
Returns opposite radian. Same twin energy, but in radians π
π angle_c($x, $y)
Calculate shortest arc in dergees β wait, degrees π β between $x and $y. Shortest path only, she does not take the scenic route.
(The original really did spell it "dergees". We cherish her.)
π angle_c_rad($x, $y)
Calculates the shortest arc in radians between $x and $y.
π angle_s($x1, $y1, $x2, $y2)
Calculates the arc between 2 points on a sphere. Expected arguments: 2 pairs of coordinates (X, Y) of the 2 points π
The coordinates may be ecliptic, equatorial or horizontal β she's not picky, she's flexible.
π diff_angle($a, $b, $mode='degrees')
Returns the angle $b - $a, accounting for circular values. Circular math is so real.
Parameters $a and $b should be in the range 0..pi*2 or 0..360, depending on the optional $mode argument. The result will be in the range -pi..pi or -180..180. This is what lets us directly compare angles which cross through 0: 359 degress... 0 degrees... 1 degree... etc. The wrap-around is fully handled, no cap β¨
Positional Arguments
$afirst angle, in radians or degrees$bsecond angle, in radians or degrees
Named Arguments
$mode"degrees"(default) or"radians", case insensitive.
π sine($x)
Calculate sin(phi); phi in units of 1 revolution = 360 degrees. One full lap, one sine cycle π
π cart($r, $theta, $phi)
Conversion of polar coordinates (r,theta,phi) into cartesian (x,y,z). Glow-up from round to boxy π¦
Arguments
$r, distance from the origin;$theta(in radians) corresponding to[-90 deg, +90 deg];$phi(in radians) corresponding to[-360 deg, +360 deg])
Returns
Rectangular coordinates:
$x, X$y, Y$z, Z
π polar($x, $y, $z)
Conversion of cartesian coordinates (x,y,z) into polar (r,theta,phi). The reverse transformation, we love a two-way street π
Arguments
$x, X$y, Y$z, Z
Returns
$r, distance from the origin;$theta(in radians) corresponding to[-90 deg, +90 deg];$phi(in radians) corresponding to[-360 deg, +360 deg])
π quad($y_minus, $y_0, $y_plus)
Quadratic interpolation. Curve fitting time, bestie π
Finds a parabola through 3 points (-1 , y_minus), (0, Y_0), (1, y_plus), that do not lie on a straight line.
Arguments
Three y-values:
$y_minusvalue of function at x = -1$y_0value of function at x = 0$y_plusvalue of function at x = 1
Returns
$xe, abscissa of extremum (may be outside[-1, 1])$ye, Value of function at xe$root1, first root found$root2, second root found$n_root, number of roots within the interval[-1, +1]
π§ AUTHOR π§
Sergey Krushinsky, <krushi at cpan.org> β the icon who wrote all of this π
π COPYRIGHT & LICENSE π
Copyright (C) 2009-2022 by Sergey Krushinsky
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Free software, free spirit, we stan π«Ά
And that's the whole page, bestie β sign-off time: this was doc'd up as perl v5.42.2, dated 2026-02-15, and it's the Astro:...thUtils(3pm) page. Go do some math, slay π β¨
π¦ where this page comes from
- alpine 3.24: perl-astro-montenbruck-doc 1.26-r1 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms