Class Sky

java.lang.Object
uk.ac.starlink.ttools.func.Sky

public class Sky extends Object
Functions useful for working with shapes on a sphere. All angles are expressed in degrees.
Since:
13 Feb 2019
Author:
Mark Taylor
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    inSkyEllipse(double lon0, double lat0, double lonCenter, double latCenter, double rA, double rB, double posAng)
    Tests whether a given sky position is inside a given ellipse.
    static boolean
    inSkyPolygon(double lon0, double lat0, double... lonLats)
    Tests whether a given sky position is inside the polygon defined by a given set of vertices.
    static double
    midLat(double lat1, double lat2)
    Determines the latitude midway between two given latitudes.
    static double
    midLon(double lon1, double lon2)
    Determines the longitude mid-way between two given longitudes.
    static double
    skyDistance(double lon1, double lat1, double lon2, double lat2)
    Calculates the separation (distance around a great circle) of two points on the sky in degrees.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • skyDistance

      public static double skyDistance(double lon1, double lat1, double lon2, double lat2)
      Calculates the separation (distance around a great circle) of two points on the sky in degrees.

      This function is identical to skyDistanceDegrees in class CoordsDegrees.

      Parameters:
      lon1 - point 1 longitude in degrees
      lat1 - point 1 latitude in degrees
      lon2 - point 2 longitude in degrees
      lat2 - point 2 latitude in degrees
      Returns:
      angular distance between point 1 and point 2 in degrees
    • midLon

      public static double midLon(double lon1, double lon2)
      Determines the longitude mid-way between two given longitudes. In most cases this is just the mean of the two values, but this function copes correctly with the case where the given values straddle the lon=0 line.
      Parameters:
      lon1 - first longitude in degrees
      lon2 - second longitude in degrees
      Returns:
      longitude midway between the given values
      Examples:
      midLon(204.0, 203.5) = 203.75, midLon(2, 359) = 0.5
    • midLat

      public static double midLat(double lat1, double lat2)
      Determines the latitude midway between two given latitudes. This simply returns the mean of the two values, but is supplied for convenience to use alongside the midLon function.
      Parameters:
      lat1 - first latitude in degrees
      lat2 - second latitude in degrees
      Returns:
      latitude midway between the given values
      Examples:
      midLat(23.5, 24.0) = 23.75
    • inSkyEllipse

      public static boolean inSkyEllipse(double lon0, double lat0, double lonCenter, double latCenter, double rA, double rB, double posAng)
      Tests whether a given sky position is inside a given ellipse.
      Parameters:
      lon0 - test point longitude in degrees
      lat0 - test point latitude in degrees
      lonCenter - ellipse center longitude in degrees
      latCenter - ellipse center latitude in degrees
      rA - ellipse first principal radius in degrees
      rB - ellipse second principal radius in degrees
      posAng - position angle in degrees from the North pole to the primary axis of the ellipse in the direction of increasing longitude
      Returns:
      true iff test point is inside, or on the border of, the ellipse
    • inSkyPolygon

      public static boolean inSkyPolygon(double lon0, double lat0, double... lonLats)
      Tests whether a given sky position is inside the polygon defined by a given set of vertices. The bounding lines of the polygon are the minor arcs of great circles between adjacent vertices, with an extra line assumed between the first and last supplied vertex. The interior of the polygon is defined to be the smaller of the two regions separated by the boundary. The vertices are specified as a sequence of loni, lati pairs.

      The implementation of this point-in-polygon function is mostly correct, but may not be bulletproof. It ought to work for relatively small regions anywhere on the sky, but for instance it may get the sense wrong for regions that extend to cover both poles.

      Parameters:
      lon0 - test point latitude in degrees
      lat0 - test point longitude in degrees
      lonLats - 2N arguments (lon1, lat1, lon2, lat2, ..., lonN, latN) giving (longitude, latitude) vertices of an N-sided polygon in degrees
      Returns:
      true iff test point is inside, or on the border of, the polygon