public class GeometryUtils
extends java.lang.Object
Constructor and Description |
---|
GeometryUtils() |
Modifier and Type | Method and Description |
---|---|
static Vector2 |
barycentric(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 |
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 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 |
triangleCentroid(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
Vector2 centroid) |
public static Vector2 barycentric(Vector2 p, Vector2 a, Vector2 b, Vector2 c, Vector2 barycentricOut)
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;
public static float lowestPositiveRoot(float a, float b, float c)
a
- the first coefficient of the quadric equationb
- the second coefficient of the quadric equationc
- the third coefficient of the quadric equationpublic static Vector2 triangleCentroid(float x1, float y1, float x2, float y2, float x3, float y3, Vector2 centroid)
public static Vector2 quadrilateralCentroid(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 centroid)