Astro:...thUtils(3pm)

πŸ“¦ version 1.26, in alpine 3.24

πŸ’– 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..360 for angular mode, 0..24 for 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..360 for angular mode, 0..24 for 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.766666666666667
  • ddd(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

  • $t coefficient, 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: 360 for degrees, 24 for 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

  • $a first angle, in radians or degrees
  • $b second 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_minus value of function at x = -1
  • $y_0 value of function at x = 0
  • $y_plus value 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 (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