Interface GeometryUtil


public interface GeometryUtil
Class containing static methods for different calculations with geometric primitives.
Author:
Andrey Malykhanov
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    Calculates approximate distance between the first and the second geographical points, in meters.
    static double
    getAbsHeadingDifference(double heading1, double heading2)
    Returns the absolute smallest difference between two headings in radians.
    static Polyline
    getArrowPolyline(Segment segment, double arrowSize)
    Returns a polyline of 2 segments representing the "pointing" part of the arrow at the end of the specified segment.
    static Polyline
    getAveragePolyline(Point beginPoint, Point endPoint, List<Polyline> polylines, double averagingRadius)
    Returns the polyline that is the "average" polyline across the specified list of polylines.
    static Polygon
    Computes the convex hull (minimal convex polygon) for the given set of points using the Jarvis March algorithm.
    static Point[]
    getHermiteCurvePoints(Point[] basePoints, int numberOfSegments)
    Returns a series of points along a Hermite curve based on provided control points.
    static Polygon
    getRectangleAround(Point point, double width, double height)
    Returns a polygon consisting of 4 segments that is a rectangle with the specified side width and height with center at the specified point.
    static Polygon
    getRectangleByCornerPoints(Point firstCornerPoint, Point secondCornerPoint)
    Creates a Polygon instance representing an axis-aligned rectangle using two opposite corner points.
    static double
    getRelativeHeading(double heading, double basicHeading)
    Calculates the relative heading based on a reference heading.
    static Polygon
    getSquareAround(Point point, double squareSide)
    Returns a polygon consisting of 4 segments that is a square with the specified side length with center at the specified point.
    static <N, A> void
    groupAroundNode(Graph<N,A> graph, Graph<N,A>.Node groupingNode, double radius, Function<N,Point> pointExtractor, Function<A,Polyline> polylineExtractor, BiFunction<A,Polyline,A> newArcValueSupplier)
    Deprecated.
  • Method Details

    • groupAroundNode

      @Deprecated static <N, A> void groupAroundNode(Graph<N,A> graph, Graph<N,A>.Node groupingNode, double radius, Function<N,Point> pointExtractor, Function<A,Polyline> polylineExtractor, BiFunction<A,Polyline,A> newArcValueSupplier)
      Deprecated.
    • getArrowPolyline

      static Polyline getArrowPolyline(Segment segment, double arrowSize)
      Returns a polyline of 2 segments representing the "pointing" part of the arrow at the end of the specified segment.
      Parameters:
      segment - the segment at whose end to create the arrow
      arrowSize - size of the arrow
      Returns:
      polyline of 2 segments representing the "pointing" part of the arrow at the end of the specified segment
    • getHermiteCurvePoints

      static Point[] getHermiteCurvePoints(Point[] basePoints, int numberOfSegments)
      Returns a series of points along a Hermite curve based on provided control points. The Hermite curve is typically smooth and it passes through all the control points.

      The method uses a cubic polynomial formula to interpolate the points between the control points. The number of points returned will be numberOfPoints + 1, including both the starting and ending points.

      Parameters:
      basePoints - An array of Point instances representing the control points of the curve
      numberOfSegments - The number of segments between points on the curve. The actual number of points returned is numberOfPoints + 1, including the end points.
      Returns:
      An array of Point instances representing the points along the Hermite curve.
    • getRelativeHeading

      static double getRelativeHeading(double heading, double basicHeading)
      Calculates the relative heading based on a reference heading.

      This method adjusts a given heading relative to a 'basic' heading (or reference heading), effectively computing the angle between the two headings. The result represents the angular displacement needed to align the first heading with the second.

      The method ensures that the result is a positive angle less than 2 * Math.PI.

      Parameters:
      heading - The heading to be adjusted, in radians.
      basicHeading - The reference heading from which to calculate the relative heading, in radians.
      Returns:
      The adjusted heading in radians, a positive value between 0 (inclusive) and 2 * Math.PI (exclusive).
    • getAbsHeadingDifference

      static double getAbsHeadingDifference(double heading1, double heading2)
      Returns the absolute smallest difference between two headings in radians.

      This method computes the absolute difference between two angular headings, taking into account the circular nature of angles. Angles are input in radians and the output is the smallest difference considering a full 360-degree rotation, where angles wrap around after 2 * Math.PI radians.

      Parameters:
      heading1 - The first heading in radians
      heading2 - The second heading in radians
      Returns:
      The smallest absolute difference in radians between the two headings
    • getSquareAround

      static Polygon getSquareAround(Point point, double squareSide)
      Returns a polygon consisting of 4 segments that is a square with the specified side length with center at the specified point.
      Parameters:
      point - center of the square
      squareSide - side length of the square
      Returns:
      polygon consisting of 4 segments that is a square with center at the specified point
    • getRectangleAround

      static Polygon getRectangleAround(Point point, double width, double height)
      Returns a polygon consisting of 4 segments that is a rectangle with the specified side width and height with center at the specified point.
      Parameters:
      point - center of the square
      width - width of the rectangle
      height - height of the rectangle
      Returns:
      polygon consisting of 4 segments that is a rectangle with center at the specified point
    • getRectangleByCornerPoints

      static Polygon getRectangleByCornerPoints(Point firstCornerPoint, Point secondCornerPoint)
      Creates a Polygon instance representing an axis-aligned rectangle using two opposite corner points. The resulting polygon consists of four corners ordered to form a closed rectangle with non-zero area.
      Parameters:
      firstCornerPoint - the first corner point of the rectangle (order does not matter)
      secondCornerPoint - the second opposite corner point of the rectangle (order does not matter)
      Returns:
      a Polygon representing the axis-aligned rectangle formed by the points
      Throws:
      IllegalArgumentException - if the two points have the same X-coordinate or Y-coordinate, which would result in a line or point (zero-area polygon)
    • getAveragePolyline

      static Polyline getAveragePolyline(Point beginPoint, Point endPoint, List<Polyline> polylines, double averagingRadius)
      Returns the polyline that is the "average" polyline across the specified list of polylines. The resulting polyline starts at the specified begin point and ends at the specified end point. This method can return null if it fails to create an average polyline.

      Parameters:
      beginPoint - begin point of the resulting polyline
      endPoint - end point of the resulting polyline
      polylines - list of polylines being averaged
      averagingRadius - radius of averaging. The segments of the resulting polyline will be around half of this value
      Returns:
      polyline that is the "average" polyline across the specified list of polylines
    • distanceBetweenLonLatsMeters

      static double distanceBetweenLonLatsMeters(Point lonLat1, Point lonLat2)
      Calculates approximate distance between the first and the second geographical points, in meters.
      Parameters:
      lonLat1 - first geographical point (lon, lat)
      lonLat2 - second geographical point (lon, lat)
      Returns:
      Approximate distance in meters
    • getConvexPolygonForPoints

      static Polygon getConvexPolygonForPoints(List<Point> points)
      Computes the convex hull (minimal convex polygon) for the given set of points using the Jarvis March algorithm.

      Special cases:

      • Empty polygon if input list is null or empty
      • Polygon containing the original points if the original list of points contains less than 3 points
      Parameters:
      points - List of input points (may be empty or null)
      Returns:
      Polygon representing the convex hull