Package uk.ac.starlink.ttools.func
Class CoordsDegrees
- java.lang.Object
-
- uk.ac.starlink.ttools.func.CoordsDegrees
-
public class CoordsDegrees extends java.lang.Object
Functions for angle transformations and manipulations, with angles generally in degrees. In particular, methods for translating between degrees and HH:MM:SS.S or DDD:MM:SS.S type sexagesimal representations are provided.- Since:
- 11 Oct 2011
- Author:
- Mark Taylor
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
degreesToDms(double deg)
Converts an angle in degrees to a formatted degrees:minutes:seconds string.static java.lang.String
degreesToDms(double deg, int secFig)
Converts an angle in degrees to a formatted degrees:minutes:seconds string with a given number of decimal places in the seconds field.static java.lang.String
degreesToHms(double deg)
Converts an angle in degrees to a formatted hours:minutes:seconds string.static java.lang.String
degreesToHms(double deg, int secFig)
Converts an angle in degrees to a formatted hours:minutes:seconds string with a given number of decimal places in the seconds field.static double
dmsToDegrees(double deg, double min, double sec)
Converts degrees, minutes, seconds to an angle in degrees.static double
dmsToDegrees(java.lang.String dms)
Converts a formatted degrees:minutes:seconds string to an angle in degrees.static double
hmsToDegrees(double hour, double min, double sec)
Converts hours, minutes, seconds to an angle in degrees.static double
hmsToDegrees(java.lang.String hms)
Converts a formatted hours:minutes:seconds string to an angle in degrees.static double
polarDistanceDegrees(double ra1, double dec1, double radius1, double ra2, double dec2, double radius2)
Calculates the distance in three dimensional space between two points specified in spherical polar coordinates.static double
posAngDegrees(double ra1, double dec1, double ra2, double dec2)
Calculates the position angle between two points on the sky in degrees.static double
skyDistanceDegrees(double ra1, double dec1, double ra2, double dec2)
Calculates the separation (distance around a great circle) of two points on the sky in degrees.
-
-
-
Method Detail
-
degreesToDms
public static java.lang.String degreesToDms(double deg)
Converts an angle in degrees to a formatted degrees:minutes:seconds string. No fractional part of the seconds field is given.- Parameters:
deg
- angle in degrees- Returns:
- DMS-format string representing
deg
-
degreesToDms
public static java.lang.String degreesToDms(double deg, int secFig)
Converts an angle in degrees to a formatted degrees:minutes:seconds string with a given number of decimal places in the seconds field.- Parameters:
deg
- angle in degreessecFig
- number of decimal places in the seconds field- Returns:
- DMS-format string representing
deg
-
degreesToHms
public static java.lang.String degreesToHms(double deg)
Converts an angle in degrees to a formatted hours:minutes:seconds string. No fractional part of the seconds field is given.- Parameters:
deg
- angle in degrees- Returns:
- HMS-format string representing
deg
-
degreesToHms
public static java.lang.String degreesToHms(double deg, int secFig)
Converts an angle in degrees to a formatted hours:minutes:seconds string with a given number of decimal places in the seconds field.- Parameters:
deg
- angle in degreessecFig
- number of decimal places in the seconds field- Returns:
- HMS-format string representing
deg
-
dmsToDegrees
public static double dmsToDegrees(java.lang.String dms)
Converts a formatted degrees:minutes:seconds string to an angle in degrees. Delimiters may be colon, space, charactersdm[s]
, or some others. Additional spaces and leading +/- are permitted. The :seconds part is optional.- Parameters:
dms
- formatted DMS string- Returns:
- angle in degrees specified by
dms
- Throws:
java.lang.NumberFormatException
- ifdms
can't be parsed as a degrees:minutes:seconds string
-
hmsToDegrees
public static double hmsToDegrees(java.lang.String hms)
Converts a formatted hours:minutes:seconds string to an angle in degrees. Delimiters may be colon, space, charactershm[s]
, or some others. Additional spaces and leading +/- are permitted. The :seconds part is optional.- Parameters:
hms
- formatted HMS string- Returns:
- angle in degrees specified by
hms
- Throws:
java.lang.NumberFormatException
- ifdms
can't be parsed as an hours:minutes:seconds string
-
dmsToDegrees
public static double dmsToDegrees(double deg, double min, double sec)
Converts degrees, minutes, seconds to an angle in degrees.In conversions of this type, one has to be careful to get the sign right in converting angles which are between 0 and -1 degrees. This routine uses the sign bit of the
deg
argument, taking care to distinguish between +0 and -0 (their internal representations are different for floating point values). It is illegal for themin
orsec
arguments to be negative.- Parameters:
deg
- degrees part of anglemin
- minutes part of anglesec
- seconds part of angle- Returns:
- specified angle in degrees
- Throws:
java.lang.IllegalArgumentException
- if an argument after the first non-zero one is negative
-
hmsToDegrees
public static double hmsToDegrees(double hour, double min, double sec)
Converts hours, minutes, seconds to an angle in degrees.In conversions of this type, one has to be careful to get the sign right in converting angles which are between 0 and -1 hours. This routine uses the sign bit of the
hour
argument, taking care to distinguish between +0 and -0 (their internal representations are different for floating point values).- Parameters:
hour
- degrees part of anglemin
- minutes part of anglesec
- seconds part of angle- Returns:
- specified angle in degrees
- Throws:
java.lang.IllegalArgumentException
- if an argument after the first non-zero one is negative
-
skyDistanceDegrees
public static double skyDistanceDegrees(double ra1, double dec1, double ra2, double dec2)
Calculates the separation (distance around a great circle) of two points on the sky in degrees.- Parameters:
ra1
- right ascension of point 1 in degreesdec1
- declination of point 1 in degreesra2
- right ascension of point 2 in degreesdec2
- declination of point 2 in degrees- Returns:
- angular distance between point 1 and point 2 in degrees
-
posAngDegrees
public static double posAngDegrees(double ra1, double dec1, double ra2, double dec2)
Calculates the position angle between two points on the sky in degrees. The result is in the range +/-180. If point 2 is due east of point 1, the result is +90. Zero is returned if the points are coincident.- Parameters:
ra1
- right ascension of point 1 in degreesdec1
- declination of point 1 in degreesra2
- right ascension of point 2 in degreesdec2
- declination of point 2 in degrees- Returns:
- bearing in degrees of point 2 from point 1.
-
polarDistanceDegrees
public static double polarDistanceDegrees(double ra1, double dec1, double radius1, double ra2, double dec2, double radius2)
Calculates the distance in three dimensional space between two points specified in spherical polar coordinates.- Parameters:
ra1
- right ascension of point 1 in degreesdec1
- declination of point1 in degreesradius1
- distance from origin of point1ra2
- right ascension of point 2 in degreesdec2
- declination of point2 in degreesradius2
- distance from origin of point2- Returns:
- the linear distance between point1 and point2;
units are as for
radius1
andradius2
-
-