Class UtilPolygons2D_F64

java.lang.Object
georegression.geometry.UtilPolygons2D_F64

public class UtilPolygons2D_F64 extends Object
Various functions related to polygons.
  • Constructor Details

    • UtilPolygons2D_F64

      public UtilPolygons2D_F64()
  • Method Details

    • isConvex

      public static boolean isConvex(Polygon2D_F64 poly)
      Determines if the polugon is convex or concave.
      Parameters:
      poly - Polygon
      Returns:
      true if convex and false if concave
    • isSimple

      public static PolygonInfo isSimple(Polygon2D_F64 p, @Nullable @Nullable PolygonInfo result, double tol)
      Checks to see if a polygon is simple or not, see [1]. If complex then the

      [1] Numerical Recipes. Third Edition. Section 21.4

      Parameters:
      p - (Input) polygon.
      tol - (Input) tolerance for testing if lines are colinear
      Returns:
      true if simple or false if complex.
    • isSelfIntersectingBrute

      public static boolean isSelfIntersectingBrute(Polygon2D_F64 p, double tol)
      Brute force algorithm which checks for self intersection.
      Parameters:
      p - (Input) the polygon
      tol - (Input) tolerance for testing if lines are colinear
      Returns:
      true if self intersection
    • triangulate

      public static void triangulate(Polygon2D_F64 p, DogArray<ThreeIndexes> triangles)
      Triangulates the simple polygon in O(N^2). Output is represented by sets of indexes where each index is the index of the vertex in the input polygon.
      Parameters:
      p - (Input) Polygon
      triangles - (Output) Triangles.
      See Also:
    • convert

      public static void convert(Rectangle2D_F64 input, Quadrilateral_F64 output)
      Converts a rectangle into a quadrilateral
      Parameters:
      input - Rectangle.
      output - Quadrilateral. Modified.
    • convert

      public static void convert(Rectangle2D_F64 input, Polygon2D_F64 output)
      Converts a rectangle into a polygon
      Parameters:
      input - Rectangle.
      output - Polygon2D_F64. Modified.
    • convert

      public static void convert(Quadrilateral_F64 input, Polygon2D_F64 output)
      Converts a quadrilateral into a polygon
      Parameters:
      input - Quadrilateral.
      output - Polygon2D_F64. Modified.
    • convert

      public static void convert(Polygon2D_F64 input, Quadrilateral_F64 output)
      Converts a polygon into a quadrilateral
      Parameters:
      input - polygon.
      output - Quadrilateral. Modified.
    • convert

      public static void convert(RectangleLength2D_I32 input, Quadrilateral_F64 output)
      Converts a rectangle into a quadrilateral
      Parameters:
      input - Rectangle.
      output - Quadrilateral. Modified.
    • bounding

      public static void bounding(Quadrilateral_F64 quad, Rectangle2D_F64 rectangle)
      Finds the minimum area bounding rectangle around the quadrilateral.
      Parameters:
      quad - (Input) Quadrilateral
      rectangle - (Output) Minimum area rectangle
    • bounding

      public static void bounding(Polygon2D_F64 polygon, Rectangle2D_F64 rectangle)
      Finds the minimum area bounding rectangle around the quadrilateral that is aligned with coordinate system axises. This is also known as the Axis Aligned Bounding Box (AABB).
      Parameters:
      polygon - (Input) Polygon
      rectangle - (Output) Minimum area rectangle
    • bounding

      public static Rectangle2D_I32 bounding(Polygon2D_F64 polygon, @Nullable @Nullable Rectangle2D_I32 aabb)
      Finds the minimum area bounding rectangle around the quadrilateral that is aligned with coordinate system axises. This is also known as the Axis Aligned Bounding Box (AABB).
      Parameters:
      polygon - (Input) Polygon
      aabb - (Output) Minimum area rectangle a.k.a. AABB. lower extent is inclusive, upper is exclusive.
    • center

      public static Point2D_F64 center(Quadrilateral_F64 quad, @Nullable @Nullable Point2D_F64 center)
      Computes the center or average point in the quadrilateral.
      Parameters:
      quad - (Input) Quadrilateral
      center - (output) Center point of the quadrilateral. Can be null.
      Returns:
      The center point.
    • isCCW

      public static boolean isCCW(List<Point2D_F64> polygon)
      Returns true if the polygon is ordered in a counter-clockwise order. This is done by summing up the interior angles.
      Parameters:
      polygon - List of ordered points which define a polygon
      Returns:
      true if CCW and false if CW
    • isCCW

      public static boolean isCCW(Polygon2D_F64 polygon)
    • vertexAverage

      public static void vertexAverage(Polygon2D_F64 input, Point2D_F64 average)
      Computes the average of all the vertexes
      Parameters:
      input - (input) polygon
      average - (output) average point
    • isIdentical

      public static boolean isIdentical(Polygon2D_F64 a, Polygon2D_F64 b, double tol)
      Checks to see if the vertexes of the two polygon's are the same up to the specified tolerance
      Parameters:
      a - Polygon
      b - Polygon
      tol - tolerance
      Returns:
      true if identical up to tolerance or false if not
    • isEquivalent

      public static boolean isEquivalent(Polygon2D_F64 a, Polygon2D_F64 b, double tol)
      Checks to see if the vertexes of the two polygon's are the same up to the specified tolerance and allows for a shift in their order
      Parameters:
      a - Polygon
      b - Polygon
      tol - tolerance
      Returns:
      true if identical up to tolerance or false if not
    • flip

      public static void flip(Polygon2D_F64 a)
      Flips the order of points inside the polygon. The first index will remain the same will otherwise be reversed
      Parameters:
      a - Polygon of order 3 or more.
    • shiftUp

      public static void shiftUp(Polygon2D_F64 a)
      Shifts all the vertexes in the polygon up one element. Wraps around at the end
      Parameters:
      a - Polygon
    • shiftDown

      public static void shiftDown(Polygon2D_F64 a)
      Shifts all the vertexes in the polygon up one element. Wraps around at the end
      Parameters:
      a - Polygon
    • removeAlmostParallel

      public static void removeAlmostParallel(Polygon2D_F64 polygon, double tol)
      Removes a node from a polygon if the two lines its attached two are almost parallel
      Parameters:
      polygon - The polygon being modified
      tol - Tolerance in radians
    • removeAdjacentDuplicates

      public static void removeAdjacentDuplicates(Polygon2D_F64 polygon, double tol)
      Remove a point if it's identical to a neighbor
      Parameters:
      polygon - The polygon being modified
      tol - Tolerance in radians
    • hasAdjacentDuplicates

      public static boolean hasAdjacentDuplicates(Polygon2D_F64 polygon, double tol)
      Remove a point if it's identical to a neighbor
      Parameters:
      polygon - The polygon being modified
      tol - Tolerance in radians
    • averageOfClosestPointError

      public static double averageOfClosestPointError(Polygon2D_F64 model, Polygon2D_F64 target, int numberOfSamples)
      Compute the error as a function of the distance between the model and target. The target is sampled at regular intervals and for each of these points the closest point on the model is found. The returned metric is the average of difference between paired points. NOTE: A different answer will be returned depending on which polygon is the model and which one is the target.
      Parameters:
      model - Model polygon
      target - Target polygon
      Returns:
      average of closest point error