++ed by:
1 non-PAUSE user
Sergey Krushinsky
and 1 contributors

# NAME

Astro::Montenbruck::Core::MathUtils - Core mathematical routines used by Astro::Montenbruck modules.

Version 0.01

# SYNOPSIS

``````  use Astro::Montenbruck::Core::MathUtils qw/dms/;

my (\$d, \$m, \$s) = dms(55.75); # (55, 45, 0)
...``````

# SUBROUTINES

## frac(\$x)

Fractional part of a decimal number.

## frac360(\$x)

Range function, similar to "to_range(\$x, \$range)", used with polinomial function for better accuracy.

## dms(\$x)

Given decimal hours (or degrees), return nearest hours (or degrees), int, minutes, int, and seconds, float.

### Positional arguments:

• decimal value, 0..360 for angular mode, 0..24 for time

### Named arguments:

• places (optional) amount of required sexagesimal values to be returned (1-3); default = 3 (degrees/hours, minutes, seconds)

### Returns:

• array of degrees (int), minutes (int), seconds (float)

Alias for "dms"

## zdms(\$x)

Converts decimal degrees to zodiac sign number (zero based), zodiac degrees, minutes and seconds.

### 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]])

Converts sexagesimal values to decimal.

### Arguments

1 to 3 sexagesimal values, such as: degrees, minutes and seconds, or degrees and minutes, or just degrees:

• `ddd(11)`

• `ddd(11, 46)`

• `ddd(11, 46, 20)`

If any non-zero argument is negative, the result is negative.

• `ddd(-11, 46, 0) = -11.766666666666667`

• `ddd(11, -46, 0) = 11.766666666666667`

### Returns:

• decimal (degrees or hours)

## polynome(\$t, @terms)

Calculates polynome: \$a1 + \$a2*\$t + \$a3*\$t*\$t + \$a4*\$t*\$t*\$t...

### 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

### Arguments

• number to reduce

• limit (non-inclusive), e.g: 360 for degrees, 24 for hours

• number

## reduce_deg(\$x)

Reduces \$x to 0 >= \$x < 360

Reduces \$x to 0 >= \$x < pi2

## opposite_deg(\$x)

Returns opposite degree.

## angle_c(\$x, \$y)

Calculate shortest arc in dergees between \$x and \$y.

Calculates shortest arc in radians between \$x and \$y.

## angle_s(\$x1, \$y1, \$x2, \$y2)

Calculates 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.

## diff_angle(\$a, \$b, \$mode='degrees')

Return angle `\$b - \$a`, accounting for circular values.

Parameters \$a and \$b should be in the range 0..pi*2 or 0..360, depending on optional \$mode argument. The result will be in the range -pi..pi or -180..180. This allows us to directly compare angles which cross through 0: 359 degress... 0 degrees... 1 degree... etc.

### 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

## cart(\$r, \$theta, \$phi)

Conversion of polar coordinates (r,theta,phi) into cartesian (x,y,z).

### 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).

• \$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])

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>`