Astro:...:Angle(3pm)

πŸ“¦ version 0.23, in alpine 3.24

πŸ’« Astro:...:Angle β€” a whole entire angle class, bestie ✨

So this is one of those User Contributed Perl Documentation pages (iykyk), and honestly? It ate. It's Astro::Coords::Angle, and it's here to hold an angle for you so Astro::Coords doesn't have to. 🫢


🌸 NAME 🌸

Astro::Coords::Angle β€” the representation of an angle. That's it, that's the vibe. πŸ’…


✨ SYNOPSIS ✨

okay so here's the whole group chat in action:

use Astro::Coords::Angle;

$ang = new Astro::Coords::Angle( 45.5, units => 'deg' );
$ang = new Astro::Coords::Angle( "45:30:00", units => 'sexagesimal' );

$rad = $ang->radians;
$deg = $ang->degrees;
$asec = $ang->arcsec;
$amin = $ang->arcmin;
$string = $ang->string;

like, make an angle, then get it back in literally whatever format you want. main character energy fr. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

It's a helper class for Astro::Coords whose whole job is representing an angle. πŸŽ€

The methods let you parse angles in sexagesimal format, and also let you return angles in any format you desire. That's the whole gig. No cap.


πŸ’œ METHODS πŸ’œ

🧚 Constructor

  • new β€” constructs a brand new Angle object. You must call it with an angle as the first argument. Optional hash arguments can be supplied to specify, for example, the units of the supplied angle.
$ang = new Astro::Coords::Angle( $angle,
                                 units => "degrees" );

The supported options are:

  • units β€” units of the supplied string or number
  • range β€” restricted range of the angle

The supported units are:

  • sexagesimal β€” a string of format either dd:mm:ss or "dd mm ss". "dms" separators are also supported.
  • degrees β€” decimal degrees
  • radians β€” radians
  • arcsec β€” arc seconds (abbreviated form is 'as')
  • arcmin β€” arc minutes (abbreviated form is 'am')

The units can be abbreviated to the first 3 characters. ⭐

If the units are not supplied, the default is to assume:

  • "sexagesimal" if the supplied string contains spaces or colons or the characters "d", "m" or "s"
  • "degrees" if the supplied number is greater than 2*PI (6.28)
  • "radians" for all other values

Negative angles are supported. πŸ™ˆ

The options for range are documented in the "range" method, bestie β€” go look.

If the angle can not be decoded (if a string), the constructor will fail. Like, it just will. πŸ’€

🌈 Accessor Methods

  • radians β€” return the angle in radians.
$rad = $ang->radians;
  • degrees β€” return the angle in decimal degrees.
$deg = $ang->degrees;
  • str_ndp β€” number of decimal places to use when stringifying the object. Default is to use the global class value (see the "NDP" class method). Set to undef to revert to the class setting.
$ang->str_ndp( 4 );
$ndp = $ang->str_ndp;
  • str_delim β€” delimiter to use between components when stringifying. Default is to use the global class value (see the "DELIM" class method). Set to undef to revert to the class setting.
$ang->str_delim( ":" );
$delim = $ang->str_delim;
  • components β€” return an array of components that correspond to the sign, degrees, arcminutes and arcseconds of the angle. The sign will be either a '+' or '-' and is required to distinguish '+0' from '-0'. (yes, that's a real problem, and no, we're not over it 😭)
@comp = $ang->components;

The number of decimal places in the seconds will not be constrained by the setting of "str_ndp", but is constrained by an optional argument:

@comp = $ang->components( $ndp );

Default resolution is 5 decimal places. The limit is 9, to avoid overflowing the results from palDr2af or palDr2tf. 🫑

In scalar context, returns a reference to an array.

  • string β€” return the angle as a string in sexagesimal format (e.g. 12:30:52.4).
$string = $ang->string();

The form of this string depends on the "str_delim" and "str_ndp" settings, and on whether the angular range allows negative values (the sign will be dropped if the range is known to be positive). πŸ’…

  • arcsec β€” return the angle in arcseconds.
$asec = $ang->arcsec;
  • arcmin β€” return the angle in arcminutes.
$amin = $ang->arcmin;
  • range β€” a string describing the allowed range of the angle. The allowed values are:
NONE         - no pre-determined range
2PI          - 0 to 2*PI radians (0 to 360 degrees)
PI           - -PI to +PI radians (-180 to 180 degrees)

Any other strings will be ignored (and a warning issued if appropriate). 🫠

When a new value is provided, the angle is normalised to this range. Note that this is not always reversible (especially if reverting to "NONE"). The range can also be specified to the constructor.

Default is not to normalize the angle.

  • in_format β€” simple wrapper method to support the backwards compatibility interface in Astro::Coords when requesting an angle by using a string format rather than an explicit method.
$angle = $ang->in_format( 'sexagesimal' );

The supported formats are:

  • radians β€” calls the 'radians' method
  • degrees β€” calls the 'degrees' method
  • sexagesimal β€” calls the 'string' method
  • array β€” calls the 'components' method (returns 2 dp resolution)
  • arcsec β€” calls the 'arcsec' method
  • arcmin β€” calls the 'arcmin' method

The format can be abbreviated to the first 3 letters, or 'am' or 'as' for arcmin and arcsec respectively. If no format is specified explicitly, the object itself will be returned. 🎁

  • clone β€” create a new cloned copy of this object.
$clone = $ang->clone;
  • negate β€” negate the sense of the angle, returning a new angle object.
$neg = $ang->negate;
Not allowed if the range is defined as 0 to 2PI. Sorry bestie, them's the rules. 🚫

πŸŽ€ Overloading

The object is overloaded such that it stringifies via the "string" method, and returns the angle in radians in numify context. So it just behaves β€” iconic. ✨

🌟 Class Methods

The following methods control the default behaviour of the class.

  • NDP β€” the number of decimal places to use in the fractional part of the number when stringifying (from either the "string" method or the "components" method).
Astro::Coords::Angle->NDP( 4 );

Default value is 2. If this is changed then all instances will be affected on stringification, unless the "str_ndp" attribute has been set explicitly for an instance.

If an undefined argument is supplied, the class will revert to its initial state.

Astro::Coords::Angle->NDP( undef );
  • DELIM β€” delimiter to use to separate components of a sexagesimal triplet when the object is stringified. If this is changed then all instances will be affected on stringification, unless the "str_delim" attribute has been set explicitly for an instance.

Common values are a colon (12:52:45.4) or a space (12 52 45.4). If more than one character is present in the string, each character will be used in turn as a delimiter in the string until either no more gaps are present (or characters have been exhausted). In the former, if there are more characters than gaps, the first character remaining in the string will be appended; in the latter case, no more characters will be printed. For example, "dms" would result in '12d52m45.4s', whereas 'dm' would result in '12d52m45.4'. 🀯

Astro::Coords::Angle->DELIM( ':' );

Default is ":". An undefined argument will result in the class reverting to the default state.

  • to_radians β€” low level utility routine to convert an input value in a specified format to radians. This method uses the same code as the object constructor to parse the supplied input argument, but does not require the overhead of object construction if the result is only to be used transiently. (efficiency queen πŸ‘‘)
$rad = Astro::Coords::Angle->to_radians( $string, $format );

See the constructor documentation for the supported format strings.


🌸 AUTHOR 🌸

Tim Jenness <t.jenness@cpan.org> 🫢


Copyright (C) 2004-2005 Tim Jenness. All Rights Reserved.

This program 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 of the License, or (at your option) any later version.

This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,Suite 330, Boston, MA 02111-1307, USA


okay that's the whole page, mwah πŸ’‹ β€” this one's perl v5.42.2, dated 2026-02-15, filed under Astro:...:Angle(3pm), and yes I remembered all of it, you're welcome bestie πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from