Package arc.math.geom

Class Geometry

java.lang.Object
arc.math.geom.Geometry

public final class Geometry extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Point2[]
    Points representing cardinal directions, starting at the left and going counter-clockwise.
    static final Point2[]
    Points representing cardinal directions, starting at the left and going counter-clockwise.
    static final int[]
     
    static final int[]
     
    static final Point2[]
     
    static final Point2[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Returns true if the barycentric coordinates are inside the triangle.
    static void
    circle(int x, int y, int width, int height, int radius, Intc2 cons)
     
    static void
    circle(int x, int y, int radius, Intc2 cons)
     
    static boolean
    colinear(float x1, float y1, float x2, float y2, float x3, float y3)
     
    static Point2
    d4(int i)
     
    static int
    d4x(int i)
     
    static int
    d4y(int i)
     
    static Point2
    d8(int i)
     
    static Point2
    d8edge(int i)
     
    static void
    ensureCCW(float[] polygon)
     
    static void
    ensureCCW(float[] polygon, int offset, int count)
     
    static <T extends Position>
    T
    findClosest(float x, float y, Iterable<T> list)
     
    static <T extends Position>
    T
    findClosest(float x, float y, T[] list)
     
    static <T extends Position>
    T
    findFurthest(float x, float y, Iterable<T> list)
     
    static float
    fromBarycoord(Vec2 barycentric, float a, float b, float c)
    Returns an interpolated value given the barycentric coordinates of a point in a triangle and the values at each vertex.
    static Vec2
    fromBarycoord(Vec2 barycentric, Vec2 a, Vec2 b, Vec2 c, Vec2 interpolatedOut)
    Returns interpolated values given the barycentric coordinates of a point in a triangle and the values at each vertex.
    static Point2[]
     
    static Point2[]
     
    static Point2[]
     
    static boolean
    isClockwise(float[] polygon, int offset, int count)
     
    static float
    iterateLine(float start, float x1, float y1, float x2, float y2, float segment, Floatc2 pos)
     
    static void
    iteratePolygon(Floatc2 path, float[] vertices)
     
    static void
    iteratePolySegments(float[] vertices, Floatc4 it)
     
    static float
    lowestPositiveRoot(float a, float b, float c)
    Returns the lowest positive root of the quadric equation given by a* x * x + b * x + c = 0.
    static Vec2
    overlap(Rect a, Rect b, boolean x)
    Checks for collisions between two rectangles, and returns the correct delta vector of A.
    static Vec2[]
    pixelCircle(float tindex)
     
    static Vec2[]
    pixelCircle(float index, Geometry.SolidChecker checker)
     
    static float
    polygonArea(float[] polygon, int offset, int count)
    Computes the area for a convex polygon.
    static Vec2
    polygonCentroid(float[] polygon, int offset, int count, Vec2 centroid)
    Returns the centroid for the specified non-self-intersecting polygon.
    static Vec2
    quadrilateralCentroid(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vec2 centroid)
     
    static boolean
    raycast(int x0f, int y0f, int x1, int y1, Geometry.Raycaster cons)
     
    static Vec2
    raycastRect(float startx, float starty, float endx, float endy, float x, float y, float halfx, float halfy)
     
    static Vec2
    raycastRect(float startx, float starty, float endx, float endy, Rect rect)
     
    static float[]
    regPoly(int amount, float size)
    returns a regular polygon with {amount} sides
    static Vec2
    toBarycoord(Vec2 p, Vec2 a, Vec2 b, Vec2 c, Vec2 barycentricOut)
    Computes the barycentric coordinates v,w for the specified point in the triangle.
    static float
    triangleArea(float x1, float y1, float x2, float y2, float x3, float y3)
     
    static Vec2
    triangleCentroid(float x1, float y1, float x2, float y2, float x3, float y3, Vec2 centroid)
     
    static Vec2
    triangleCircumcenter(float x1, float y1, float x2, float y2, float x3, float y3, Vec2 circumcenter)
    Returns the circumcenter of the triangle.
    static float
    triangleCircumradius(float x1, float y1, float x2, float y2, float x3, float y3)
     
    static float
    triangleQuality(float x1, float y1, float x2, float y2, float x3, float y3)
    Ratio of circumradius to shortest edge as a measure of triangle quality.
    static FloatSeq
     

    Methods inherited from class java.lang.Object

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

    • d4

      public static final Point2[] d4
      Points representing cardinal directions, starting at the left and going counter-clockwise.
    • d4c

      public static final Point2[] d4c
      Points representing cardinal directions, starting at the left and going counter-clockwise. Also contains a center point: 0,0.
    • d4x

      public static final int[] d4x
    • d4y

      public static final int[] d4y
    • d8

      public static final Point2[] d8
    • d8edge

      public static final Point2[] d8edge
  • Constructor Details

    • Geometry

      public Geometry()
  • Method Details

    • d4

      public static Point2 d4(int i)
    • d4x

      public static int d4x(int i)
    • d4y

      public static int d4y(int i)
    • d8

      public static Point2 d8(int i)
    • d8edge

      public static Point2 d8edge(int i)
    • circle

      public static void circle(int x, int y, int radius, Intc2 cons)
    • circle

      public static void circle(int x, int y, int width, int height, int radius, Intc2 cons)
    • vectorsToFloats

      public static FloatSeq vectorsToFloats(Seq<Vec2> result)
    • findClosest

      public static <T extends Position> T findClosest(float x, float y, T[] list)
    • findClosest

      public static <T extends Position> T findClosest(float x, float y, Iterable<T> list)
    • findFurthest

      public static <T extends Position> T findFurthest(float x, float y, Iterable<T> list)
    • pixelCircle

      public static Vec2[] pixelCircle(float tindex)
    • pixelCircle

      public static Vec2[] pixelCircle(float index, Geometry.SolidChecker checker)
    • regPoly

      public static float[] regPoly(int amount, float size)
      returns a regular polygon with {amount} sides
    • iterateLine

      public static float iterateLine(float start, float x1, float y1, float x2, float y2, float segment, Floatc2 pos)
    • iteratePolySegments

      public static void iteratePolySegments(float[] vertices, Floatc4 it)
    • iteratePolygon

      public static void iteratePolygon(Floatc2 path, float[] vertices)
    • getD4Points

      public static Point2[] getD4Points()
    • getD8Points

      public static Point2[] getD8Points()
    • getD8EdgePoints

      public static Point2[] getD8EdgePoints()
    • raycast

      public static boolean raycast(int x0f, int y0f, int x1, int y1, Geometry.Raycaster cons)
    • raycastRect

      public static Vec2 raycastRect(float startx, float starty, float endx, float endy, Rect rect)
    • raycastRect

      public static Vec2 raycastRect(float startx, float starty, float endx, float endy, float x, float y, float halfx, float halfy)
    • overlap

      public static Vec2 overlap(Rect a, Rect b, boolean x)
      Checks for collisions between two rectangles, and returns the correct delta vector of A. Note: The same vector instance is returned each time!
    • toBarycoord

      public static Vec2 toBarycoord(Vec2 p, Vec2 a, Vec2 b, Vec2 c, Vec2 barycentricOut)
      Computes the barycentric coordinates v,w for the specified point in the triangle.

      If barycentric.x >= 0 && barycentric.y >= 0 && barycentric.x + barycentric.y <= 1 then the point is inside the triangle.

      If vertices a,b,c have values aa,bb,cc then to get an interpolated value at point p:

       Geometry.barycentric(p, a, b, c, barycentric);
       float u = 1.f - barycentric.x - barycentric.y;
       float x = u * aa.x + barycentric.x * bb.x + barycentric.y * cc.x;
       float y = u * aa.y + barycentric.x * bb.y + barycentric.y * cc.y;
       
      Returns:
      barycentricOut
    • barycoordInsideTriangle

      public static boolean barycoordInsideTriangle(Vec2 barycentric)
      Returns true if the barycentric coordinates are inside the triangle.
    • fromBarycoord

      public static Vec2 fromBarycoord(Vec2 barycentric, Vec2 a, Vec2 b, Vec2 c, Vec2 interpolatedOut)
      Returns interpolated values given the barycentric coordinates of a point in a triangle and the values at each vertex.
      Returns:
      interpolatedOut
    • fromBarycoord

      public static float fromBarycoord(Vec2 barycentric, float a, float b, float c)
      Returns an interpolated value given the barycentric coordinates of a point in a triangle and the values at each vertex.
      Returns:
      interpolatedOut
    • lowestPositiveRoot

      public static float lowestPositiveRoot(float a, float b, float c)
      Returns the lowest positive root of the quadric equation given by a* x * x + b * x + c = 0. If no solution is given Float.Nan is returned.
      Parameters:
      a - the first coefficient of the quadric equation
      b - the second coefficient of the quadric equation
      c - the third coefficient of the quadric equation
      Returns:
      the lowest positive root or Float.Nan
    • colinear

      public static boolean colinear(float x1, float y1, float x2, float y2, float x3, float y3)
    • triangleCentroid

      public static Vec2 triangleCentroid(float x1, float y1, float x2, float y2, float x3, float y3, Vec2 centroid)
    • triangleCircumcenter

      public static Vec2 triangleCircumcenter(float x1, float y1, float x2, float y2, float x3, float y3, Vec2 circumcenter)
      Returns the circumcenter of the triangle. The input points must not be colinear.
    • triangleCircumradius

      public static float triangleCircumradius(float x1, float y1, float x2, float y2, float x3, float y3)
    • triangleQuality

      public static float triangleQuality(float x1, float y1, float x2, float y2, float x3, float y3)
      Ratio of circumradius to shortest edge as a measure of triangle quality.

      Gary L. Miller, Dafna Talmor, Shang-Hua Teng, and Noel Walkington. A Delaunay Based Numerical Method for Three Dimensions: Generation, Formulation, and Partition.

    • triangleArea

      public static float triangleArea(float x1, float y1, float x2, float y2, float x3, float y3)
    • quadrilateralCentroid

      public static Vec2 quadrilateralCentroid(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vec2 centroid)
    • polygonCentroid

      public static Vec2 polygonCentroid(float[] polygon, int offset, int count, Vec2 centroid)
      Returns the centroid for the specified non-self-intersecting polygon.
    • polygonArea

      public static float polygonArea(float[] polygon, int offset, int count)
      Computes the area for a convex polygon.
    • ensureCCW

      public static void ensureCCW(float[] polygon)
    • ensureCCW

      public static void ensureCCW(float[] polygon, int offset, int count)
    • isClockwise

      public static boolean isClockwise(float[] polygon, int offset, int count)