libgdx API

## Class GeometryUtils

• java.lang.Object

• ```public final class GeometryUtils
extends java.lang.Object```
Author:
Nathan Sweet
• ### Constructor Summary

Constructors
Constructor and Description
`GeometryUtils()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static boolean` `barycoordInsideTriangle(Vector2 barycentric)`
Returns true if the barycentric coordinates are inside the triangle.
`static boolean` ```colinear(float x1, float y1, float x2, float y2, float x3, float y3)```
`static void` `ensureCCW(float[] polygon)`
`static void` ```ensureCCW(float[] polygon, int offset, int count)```
`static float` ```fromBarycoord(Vector2 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 Vector2` ```fromBarycoord(Vector2 barycentric, Vector2 a, Vector2 b, Vector2 c, Vector2 interpolatedOut)```
Returns interpolated values given the barycentric coordinates of a point in a triangle and the values at each vertex.
`static boolean` ```isClockwise(float[] polygon, int offset, int count)```
`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 float` ```polygonArea(float[] polygon, int offset, int count)```
Computes the area for a convex polygon.
`static Vector2` ```polygonCentroid(float[] polygon, int offset, int count, Vector2 centroid)```
Returns the centroid for the specified non-self-intersecting polygon.
`static Vector2` ```quadrilateralCentroid(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 centroid)```
`static Vector2` ```toBarycoord(Vector2 p, Vector2 a, Vector2 b, Vector2 c, Vector2 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 Vector2` ```triangleCentroid(float x1, float y1, float x2, float y2, float x3, float y3, Vector2 centroid)```
`static Vector2` ```triangleCircumcenter(float x1, float y1, float x2, float y2, float x3, float y3, Vector2 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.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### GeometryUtils

`public GeometryUtils()`
• ### Method Detail

• #### toBarycoord

```public static Vector2 toBarycoord(Vector2 p,
Vector2 a,
Vector2 b,
Vector2 c,
Vector2 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:

``` GeometryUtils.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(Vector2 barycentric)`
Returns true if the barycentric coordinates are inside the triangle.
• #### fromBarycoord

```public static Vector2 fromBarycoord(Vector2 barycentric,
Vector2 a,
Vector2 b,
Vector2 c,
Vector2 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(Vector2 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 Vector2 triangleCentroid(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
Vector2 centroid)```
• #### triangleCircumcenter

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

```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)```

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

```public static Vector2 polygonCentroid(float[] polygon,
int offset,
int count,
Vector2 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)```