Class LocationElement

  • All Implemented Interfaces:
    java.io.Serializable

    public class LocationElement
    extends java.lang.Object
    implements java.io.Serializable
    This is a convenience class used for passing around spherical coordinates. Units are radians for longitude and latitude, AU for distance.
    Author:
    talonso
    See Also:
    Serialized Form
    • Constructor Detail

      • LocationElement

        public LocationElement()
        Default constructor.
      • LocationElement

        public LocationElement​(double lon,
                               double lat,
                               double rad)
        Explicit constructor.
        Parameters:
        lon - longitude.
        lat - latitude.
        rad - radius.
      • LocationElement

        public LocationElement​(double[] vector)
        Vector constructor.
        Parameters:
        vector - { lon, lat, rad }
    • Method Detail

      • getLatitude

        public double getLatitude()
        Gets the latitude.
        Returns:
        The latitude value of this instance.
      • getLongitude

        public double getLongitude()
        Gets the longitude.
        Returns:
        The longitude value of this instance.
      • getRadius

        public double getRadius()
        Gets the radius.
        Returns:
        The radius value of this instance.
      • get

        public double[] get()
        Get all values in this instance as a vector.

        The vector is an array of three doubles, longitude, latitude, radius.

        Returns:
        v[0] = longitude, v[1] = latitude, v[2] = radius.
      • setRadius

        public void setRadius​(double d)
        Set the radius.
        Parameters:
        d - The new radius value.
      • set

        public void set​(double[] vector)
        Set all members of this instance from a vector.

        The vector is an array of three doubles, longitude, latitude, radius, in that order.

        Parameters:
        vector - v[0] = longitude, v[1] = latitude, v[2] = radius.
      • set

        public void set​(double lon,
                        double lat,
                        double rad)
        Set all members of this instance individually.
        Parameters:
        lon - The new longitude.
        lat - The new latitude.
        rad - The new radius.
      • parseRectangularCoordinates

        public static LocationElement parseRectangularCoordinates​(double[] v)
        Transforms rectangular coordinates x, y, z contained in an array to a LocationElement. Coordinate system is independent: equatorial, ecliptic, or any other.
        Parameters:
        v - (x, y, z) vector.
        Returns:
        Location object.
      • parseRectangularCoordinatesFast

        public static LocationElement parseRectangularCoordinatesFast​(double[] v)
        Transforms rectangular coordinates x, y, z contained in an array to a LocationElement. Coordinate system is independent: equatorial, ecliptic, or any other. This method uses FastMath.atan2(double, double) and FastMath.asin(double) methods.
        Parameters:
        v - (x, y, z) vector.
        Returns:
        Location object.
      • parseRectangularCoordinatesFast

        public static LocationElement parseRectangularCoordinatesFast​(double x,
                                                                      double y,
                                                                      double z)
        Transforms rectangular coordinates x, y, z contained in an array to a LocationElement. Coordinate system is independent: equatorial, ecliptic, or any other. This method calls parseRectangularCoordinatesFast(double[]).
        Parameters:
        x - X coordinate.
        y - Y coordinate.
        z - Z coordinate.
        Returns:
        Location object.
      • parseRectangularCoordinates

        public static LocationElement parseRectangularCoordinates​(double x,
                                                                  double y,
                                                                  double z)
        Transforms rectangular coordinates x, y, z to a LocationElement. Coordinate system is independent: equatorial, ecliptic, or any other.
        Parameters:
        x - X coordinate.
        y - Y coordinate.
        z - Z coordinate.
        Returns:
        Location object.
      • parseLocationElement

        public static double[] parseLocationElement​(LocationElement loc)
        Transforms a LocationElement into a set of rectangular coordinates x, y, z.
        Parameters:
        loc - Location object.
        Returns:
        Array with (x, y, z) vector.
      • parseLocationElementFast

        public static double[] parseLocationElementFast​(LocationElement loc)
        Transforms a LocationElement into a set of rectangular coordinates x, y, z, using approximate trigonometric functions.
        Parameters:
        loc - Location object.
        Returns:
        Array with (x, y, z) vector.
      • getRectangularCoordinates

        public double[] getRectangularCoordinates()
        Transforms a LocationElement into a set of rectangular coordinates x, y, z.
        Returns:
        Array with (x, y, z) vector.
      • getLinearDistance

        public static double getLinearDistance​(LocationElement loc1,
                                               LocationElement loc2)
        Obtain linear distance between two spherical positions.
        Parameters:
        loc1 - Location object.
        loc2 - Location object.
        Returns:
        Linear distance.
      • getMidPoint

        public static LocationElement getMidPoint​(LocationElement loc1,
                                                  LocationElement loc2)
        Obtain the direction between two spherical positions.
        Parameters:
        loc1 - Location object.
        loc2 - Location object.
        Returns:
        The midpoint.
      • solveSphericalTriangle

        public static double solveSphericalTriangle​(LocationElement locA,
                                                    LocationElement locP,
                                                    LocationElement locP1,
                                                    boolean approx)
        Solves an spherical triangle return the angle between the positions locP and locP1 as seen from locA.
        Parameters:
        locA - A position.
        locP - P position.
        locP1 - P1 position.
        approx - True for an approximate and faster computation.
        Returns:
        The spherical angle.
      • getAngularDistance

        public static double getAngularDistance​(LocationElement loc1,
                                                LocationElement loc2)
        Obtain angular distance between two spherical coordinates.
        Parameters:
        loc1 - Location object.
        loc2 - Location object.
        Returns:
        The distance in radians, from 0 to PI.
      • getApproximateAngularDistance

        public static double getApproximateAngularDistance​(LocationElement loc1,
                                                           LocationElement loc2)
        Obtain approximate angular distance between two spherical coordinates. Almost exact result
        Parameters:
        loc1 - Location object.
        loc2 - Location object.
        Returns:
        The distance in radians, from 0 to PI.
      • getApproximatePositionAngle

        public static double getApproximatePositionAngle​(LocationElement loc1,
                                                         LocationElement loc2)
        Obtain position angle between two spherical coordinates. Good performance.
        Parameters:
        loc1 - Location object.
        loc2 - Location object.
        Returns:
        The position angle in radians.
      • getPositionAngle

        public static double getPositionAngle​(LocationElement loc1,
                                              LocationElement loc2)
        Obtain exact position angle between two spherical coordinates. Performance will be poor.
        Parameters:
        loc1 - Location object.
        loc2 - Location object.
        Returns:
        The position angle in radians.
      • equals

        public boolean equals​(java.lang.Object o)
        Returns true if the input object is equals to this instance.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a String representation of this object.
        Overrides:
        toString in class java.lang.Object
      • move

        public void move​(double dlon,
                         double dlat,
                         double dr)
        Moves this position a given amount in each axis.
        Parameters:
        dlon - Displacement in longitude, radians. It is a pure incremental modification.
        dlat - Displacement in latitude, radians.
        dr - Displacemente in distance, in units of the distance.
      • toOffset

        public void toOffset​(double dlon,
                             double dlat)
        Moves this position a given amount in each axis, setting the location to a given point with some offset.
        Parameters:
        dlon - Displacement in longitude, radians. This increment is respect the sky plain, not a coordinate incremental offset.
        dlat - Displacement in latitude, radians.