java实现凸包算法_JAVA语⾔中实现凸包算法源码⼀:JarvisMarch.java
package mtn.vex;
import static java.lang.Math.abs;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class JarvisMarch {
private int count;
public int getCount() {
return count;
}
public void tCount(int count) {
}
private static int MAX_ANGLE = 4;
private double currentMinAngle = 0;
private List hullPointList;
private List indexList;
private PointFactory pf;
private Point[] ps;
public Point[] getPs() {
return ps;
}
private int firstIndex;
public int getFirstIndex() {
return firstIndex;
}
public JarvisMarch() {
this(10);
亚诺夫
}
public JarvisMarch(int count) {
pf = Instance(count);
initialize();
考试什么都去死吧
}
public JarvisMarch(int[] x, int[] y) {
pf = Instance(x, y);
排球上手发球
initialize();
}
private void initialize() {
hullPointList = new LinkedList();
indexList = new LinkedList();
firstIndex = pf.getFirstIndex();
ps = pf.getPoints();
addToHull(firstIndex);
}
private void addToHull(int index) {
indexList.add(index);
hullPointList.add(ps[index]);
}
public int calculateHull() {
for (int i = getNextIndex(firstIndex); i != firstIndex; i = getNextIndex(i)) { addToHull(i);
胡桃夹子3d
}
showHullPoints();
return 0;
}
private void showHullPoints() {
Iterator itPoint = hullPointList.iterator();
Iterator itIndex = indexList.iterator();
Point p;
int i;
int index = 0;
System.out.println("The hull points is: -> ");
while (itPoint.hasNext()) {
i = ();
p = ();
大班益智区目标System.out.print(i + ":(" + p.getX() + "," + p.getY() + ") ");
index++;
if (index % 10 == 0)
System.out.println();
}
System.out.println();
System.out.println("****************************************************************"); System.out.println("The count of all hull points is " + index);
}
public int getNextIndex(int currentIndex) {
double minAngle = MAX_ANGLE;
double pudoAngle;送别简谱
实习协议书int minIndex = 0;
for (int i = 0; i < ps.length; i++) {
if (i != currentIndex) {
pudoAngle = getPudoAngle(ps[i].getX() - ps[currentIndex].getX(), ps[i].getY() - ps[currentIndex].getY());
if (pudoAngle >= currentMinAngle && pudoAngle < minAngle) { minAngle = pudoAngle;骗的英文单词
minIndex = i;
} el if (pudoAngle == minAngle){
if((abs(ps[i].getX() - ps[currentIndex].getX()) >
abs(ps[minIndex].getX() - ps[currentIndex