use of de.fhg.igd.geom.algorithm.FaceTriangulation in project hale by halestudio.
the class AreaCalc method triangulate.
/**
* Triangulates the polygon.
*
* @param pos List of {@link GeoPosition}
*
* @return List of {@link Triangle}
*/
private List<Triangle> triangulate(List<GeoPosition> pos) {
// contains all triangles
List<Triangle> triangles = new ArrayList<Triangle>(pos.size() - 1);
// standard epsg code
int epsg = pos.get(0).getEpsgCode();
// check if it's already a triangle
if (pos.size() == 3) {
triangles.add(new Triangle(pos.get(0), pos.get(1), pos.get(2)));
return triangles;
}
// contains all points from the surface
List<Point3D> face = new ArrayList<>();
// convert Point2D to Vertex
for (int i = 0; i < pos.size(); i++) {
GeoPosition p = pos.get(i);
face.add(new Point3D(p.getX(), p.getY(), 0.0));
}
// create FaceSet and triangulate
FaceTriangulation fst = new FaceTriangulation();
List<List<Point3D>> faces = fst.triangulateFace(face);
// convert
for (List<Point3D> f : faces) {
// create GeoPositions
GeoPosition p1, p2, p3;
p1 = new GeoPosition(f.get(0).getX(), f.get(0).getY(), epsg);
p2 = new GeoPosition(f.get(1).getX(), f.get(1).getY(), epsg);
p3 = new GeoPosition(f.get(2).getX(), f.get(2).getY(), epsg);
// add triangle
triangles.add(new Triangle(p1, p2, p3));
}
return triangles;
}
Aggregations