I found a convex hull algorithm that orders a set of given points of a 3D convex plane after a projection to 2D. What is this algorithm called? I looked up common algorithms: jarvis march, quickhull, chan's, graham scan and none of them matches. The code:
private void buildConvexHull() {
Point3D[] projPoints = new Point3D[unorderedPoints.length];
for (int i = 0; i < unorderedPoints.length; i++) {
Point p = orthoView.project(unorderedPoints[i]); //Orthogonal projection for representing three-dimensional points in two dimensions.
projPoints[i] = new Point3D(p.x, p.y, 0.0); //projected point without third dimension
}
vertices = new Point3D[1];
//determine the point with smallest x coordinate.
Point3D bottom = projPoints[0];
vertices[0] = unorderedPoints[0];
for (int i = 1; i < projPoints.length; i++) {
if (projPoints[i].x < bottom.x) { // if (projPoints[i].y < bottom.y) {
bottom = projPoints[i];
vertices[0] = unorderedPoints[i];
}
}
Point3D p = bottom;
Point3D[] v = new Point3D[1];
v[0] = p;
do {
int i = 0;
if (projPoints[0] == p) {
i = 1;
}
Point3D candidate = projPoints[i];
HalfSpace h = new HalfSpace(p, candidate);
int index = i;
for (i = i + 1; i < projPoints.length; i++) {
if (projPoints[i] != p && h.isInside(projPoints[i]) < 0) {
candidate = projPoints[i];
h = new HalfSpace(p, candidate);
index = i;
}
}
Point3D[] vnew = new Point3D[v.length + 1];
System.arraycopy(v, 0, vnew, 0, v.length);
v = vnew;
v[v.length - 1] = candidate;
Point3D[] verticesnew = new Point3D[vertices.length + 1];
System.arraycopy(vertices, 0, verticesnew, 0, vertices.length);
vertices = verticesnew;
vertices[vertices.length - 1] = unorderedPoints[index];
p = candidate;
} while (p != bottom);
}
The class Halfspace's isInside Method:
/**
* A method checking if the given point is inside the halfspace.
*
* @return 1 if it is inside, 0 if it is on the line and otherwise -1.
*/
int isInside(Point3D x) {
Point3D n = a.normal(b, x);
double dz = n.z - a.z;
if (dz > 0) {
return 1;
} else if (dz < 0) {
return -1;
} else {
return 0;
}
}
As I understand it, the algorithm selects a point in each iteration from the set of points that do not yet belong to the convex hull and the last one that was added to the hull. Then a line is created between these two. If none of the other points is on the outer side, then the selected point is a following point and is added to the set of processed points. Is that correct?