public class Centroid
extends java.lang.Object
Geometry
of any dimension.
If the geometry is nominally of higher dimension,
but has lower effective dimension
(i.e. contains only components
having zero length or area),
the centroid will be computed as for the equivalent lower-dimension geometry.
If the input geometry is empty, a
null
Coordinate is returned.
http://www.faqs.org/faqs/graphics/algorithms-faq/
for further details of the basic approach.
Modifier and Type | Field and Description |
---|---|
private Coordinate |
areaBasePt |
private double |
areasum2 |
private Coordinate |
cg3 |
private Coordinate |
lineCentSum |
private Coordinate |
ptCentSum |
private int |
ptCount |
private double |
totalLength |
private Coordinate |
triangleCent3 |
Constructor and Description |
---|
Centroid(Geometry geom)
Creates a new instance for computing the centroid of a geometry
|
Modifier and Type | Method and Description |
---|---|
private void |
add(Geometry geom)
Adds a Geometry to the centroid total.
|
private void |
add(Polygon poly) |
private void |
addHole(Coordinate[] pts) |
private void |
addLineSegments(Coordinate[] pts)
Adds the line segments defined by an array of coordinates
to the linear centroid accumulators.
|
private void |
addPoint(Coordinate pt)
Adds a point to the point centroid accumulator.
|
private void |
addShell(Coordinate[] pts) |
private void |
addTriangle(Coordinate p0,
Coordinate p1,
Coordinate p2,
boolean isPositiveArea) |
private static double |
area2(Coordinate p1,
Coordinate p2,
Coordinate p3)
Returns twice the signed area of the triangle p1-p2-p3.
|
private static void |
centroid3(Coordinate p1,
Coordinate p2,
Coordinate p3,
Coordinate c)
Computes three times the centroid of the triangle p1-p2-p3.
|
Coordinate |
getCentroid()
Gets the computed centroid.
|
static Coordinate |
getCentroid(Geometry geom)
Computes the centroid point of a geometry.
|
private void |
setAreaBasePoint(Coordinate basePt) |
private Coordinate areaBasePt
private Coordinate triangleCent3
private double areasum2
private Coordinate cg3
private Coordinate lineCentSum
private double totalLength
private int ptCount
private Coordinate ptCentSum
public Centroid(Geometry geom)
public static Coordinate getCentroid(Geometry geom)
geom
- the geometry to useprivate void add(Geometry geom)
geom
- the geometry to addpublic Coordinate getCentroid()
private void setAreaBasePoint(Coordinate basePt)
private void add(Polygon poly)
private void addShell(Coordinate[] pts)
private void addHole(Coordinate[] pts)
private void addTriangle(Coordinate p0, Coordinate p1, Coordinate p2, boolean isPositiveArea)
private static void centroid3(Coordinate p1, Coordinate p2, Coordinate p3, Coordinate c)
private static double area2(Coordinate p1, Coordinate p2, Coordinate p3)
private void addLineSegments(Coordinate[] pts)
pts
- an array of Coordinate
sprivate void addPoint(Coordinate pt)
pt
- a Coordinate