Class GeometryUtils

java.lang.Object
org.oscim.utils.geom.GeometryUtils

public final class GeometryUtils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static float
    area(float[] points, int size)
    Returns the unsigned area of polygon.
    static float
    area(float[] a, int p1, int p2, int p3)
     
    static float
    area(float ax, float ay, float bx, float by, float cx, float cy)
     
    static float[]
    bisectionNorm2D(float[] v1, float[] v2)
     
    static float[]
    center(float[] points, int pointPos, int n, float[] out)
    Calculates the center of a set of points.
    static float[]
    closestPointOnLine2D(float[] pP, float[] pL, float[] vL)
    Calculate the closest point on a line.
    static float[]
    diffVec(float[] a, float[] b)
     
    static double
    distance(float[] p, int a, int b)
     
    static double
    distance2D(float[] a, float[] b)
     
    static float
    distancePointLine2D(float[] pP, float[] pL, float[] vL)
    Calculate the distance from a point to a line.
    static float
    dotProduct(float[] a, float[] b)
     
    static double
    dotProduct(float[] p, int a, int b, int c)
     
    static float[]
    intersectionLinePlane(float[] pL, float[] vL, float[] pP, float[] vP)
    Calculate intersection of a plane with a line
    static float[]
    intersectionLines2D(float[] pA, float[] vA, float[] pB, float[] vB)
     
    static float
    isClockwise(float[] points, int size)
    Is polygon clockwise.
    static float
    isTrisClockwise(float[] pA, float[] pB, float[] pC)
    Indicates the turn of tris pA-pB-pC.
    static double
    length(float[] vec)
     
    static float[]
    normalize(float[] vec)
     
    static List<float[]>
    normalizedVectors2D(List<float[]> points, List<Float> outLengths)
    Calculate the normalized direction vectors of point list (polygon)
    static float[]
    normalOfPlane(float[] pA, float[] pB, float[] pC)
     
    static boolean
    pointInPoly(float x, float y, float[] vertices, int length, int offset)
    Test if point x/y is in polygon defined by vertices[offset ...
    static float[]
    scale(float[] v, float scale)
     
    static float
    squaredDistance(float[] p, int a, int b)
     
    static float
    squareSegmentDistance(float[] p, int a, int b, int c)
    square distance from a point a to a segment b,c
    static float[]
    sumVec(float[] a, float[] b)
     

    Methods inherited from class java.lang.Object

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

    • pointInPoly

      public static boolean pointInPoly(float x, float y, float[] vertices, int length, int offset)
      Test if point x/y is in polygon defined by vertices[offset ... offset+length]

      -- from www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

      If there is only one connected component, then it is optional to repeat the first vertex at the end. It's also optional to surround the component with zero vertices.

      The polygon may contain multiple separate components, and/or holes, provided that you separate the components and holes with a (0,0) vertex, as follows.

    • First, include a (0,0) vertex.
    • Then include the first component' vertices, repeating its first vertex after the last vertex.
    • Include another (0,0) vertex.
    • Include another component or hole, repeating its first vertex after the last vertex.
    • Repeat the above two steps for each component and hole.
    • Include a final (0,0) vertex.

      Each component or hole's vertices may be listed either clockwise or counter-clockwise.

    • area

      public static float area(float[] points, int size)
      Returns the unsigned area of polygon.
      Parameters:
      size - the number of point coordinates
      Returns:
      unsigned polygon area
    • area

      public static float area(float ax, float ay, float bx, float by, float cx, float cy)
    • area

      public static float area(float[] a, int p1, int p2, int p3)
    • bisectionNorm2D

      public static float[] bisectionNorm2D(float[] v1, float[] v2)
      Parameters:
      v1 - the first normalized vector
      v2 - the second normalized vector
      Returns:
      the bisection of the to vectors
    • center

      public static float[] center(float[] points, int pointPos, int n, float[] out)
      Calculates the center of a set of points.
      Parameters:
      points - the points array
      pointPos - the start position of points
      n - the number of points
      out - the center output
      Returns:
      the center of points
    • closestPointOnLine2D

      public static float[] closestPointOnLine2D(float[] pP, float[] pL, float[] vL)
      Calculate the closest point on a line. See: https://en.wikipedia.org/wiki/Vector_projection#Vector_projection_2
      Parameters:
      pP - point
      pL - point of line
      vL - vector of line
      Returns:
      the closest point on line
    • diffVec

      public static float[] diffVec(float[] a, float[] b)
      Parameters:
      a - first vector
      b - second vector
      Returns:
      a - b
    • sumVec

      public static float[] sumVec(float[] a, float[] b)
      Parameters:
      a - first vector
      b - second vector
      Returns:
      a + b
    • squaredDistance

      public static float squaredDistance(float[] p, int a, int b)
    • squareSegmentDistance

      public static float squareSegmentDistance(float[] p, int a, int b, int c)
      square distance from a point a to a segment b,c
    • distance

      public static double distance(float[] p, int a, int b)
    • distance2D

      public static double distance2D(float[] a, float[] b)
      Parameters:
      a - point a[x,y]
      b - point b[x,y]
      Returns:
      the distance between a and b.
    • distancePointLine2D

      public static float distancePointLine2D(float[] pP, float[] pL, float[] vL)
      Calculate the distance from a point to a line. See: https://en.wikipedia.org/wiki/Vector_projection#Vector_projection_2
      Parameters:
      pP - point
      pL - point of line
      vL - vector of line
      Returns:
      the minimum distance between line and point
    • dotProduct

      public static double dotProduct(float[] p, int a, int b, int c)
    • dotProduct

      public static float dotProduct(float[] a, float[] b)
      Parameters:
      a - first vector
      b - second vector
      Returns:
      the dot product
    • intersectionLines2D

      public static float[] intersectionLines2D(float[] pA, float[] vA, float[] pB, float[] vB)
      Parameters:
      pA - position vector of A
      vA - direction vector of A
      pB - position vector of B
      vB - direction vector of B
      Returns:
      the intersection point
    • intersectionLinePlane

      public static float[] intersectionLinePlane(float[] pL, float[] vL, float[] pP, float[] vP)
      Calculate intersection of a plane with a line
      Parameters:
      pL - position vector of line
      vL - direction vector of line
      pP - position vector of plane
      vP - normal vector of plane
      Returns:
      the intersection point
    • isClockwise

      public static float isClockwise(float[] points, int size)
      Is polygon clockwise. Note that the coordinate system is left hand side.
      Parameters:
      points - the points array
      size - the number of point coordinates
      Returns:
      the signed area of the polygon positive: clockwise negative: counter-clockwise 0: collinear
    • isTrisClockwise

      public static float isTrisClockwise(float[] pA, float[] pB, float[] pC)
      Indicates the turn of tris pA-pB-pC. Note that the coordinate system is left hand side.
      Returns:
      positive: clockwise negative: counter-clockwise 0: collinear
    • length

      public static double length(float[] vec)
      Returns:
      the length of the vector
    • normalize

      public static float[] normalize(float[] vec)
      Returns:
      the normalized vector (with length 1)
    • normalizedVectors2D

      public static List<float[]> normalizedVectors2D(List<float[]> points, List<Float> outLengths)
      Calculate the normalized direction vectors of point list (polygon)
      Parameters:
      points - the list of 2D points
      outLengths - the optional list to store lengths of vectors
      Returns:
      the normalized direction vectors
    • normalOfPlane

      public static float[] normalOfPlane(float[] pA, float[] pB, float[] pC)
      Parameters:
      pA - first point of plane
      pB - second point of plane
      pC - third point of plane
      Returns:
      the normal of plane
    • scale

      public static float[] scale(float[] v, float scale)
      Parameters:
      v - the vector
      scale - the scale
      Returns:
      the scaled vector