int currentPoint = 2;
int direction = 1;
PVector copyOf(PVector p){
return new PVector(p.x, p.y);
}
void addPoint() {
hull.add(points.get(currentPoint));
// look at the turn direction in the last three points
// (we have to work with copies of the points because Java)
p1 = copyOf(hull.get(hull.size() - 3));
p2 = copyOf(hull.get(hull.size() - 2));
p3 = copyOf(hull.get(hull.size() - 1));
while (!crossprod (p1, p2, p3) && hull.size() > 2) {
// if crossproduct is <= 0, then remove the middle point
// if crossproduct is >= 0, do nothing because we have add the point before
hull.remove(hull.size() - 2);
if (hull.size() >= 3) {
//in case of null pointer error
p1 = copyOf(hull.get(hull.size() - 3));
}
p2 = copyOf(hull.get(hull.size() - 2));
p3 = copyOf(hull.get(hull.size() - 1));
}
//you'll see information in the console
println("currentPoint: " + currentPoint + " numPoints: " + points.size() + " hullSize: " + hull.size()+" direction:"+direction);
if (currentPoint == points.size() -1 || currentPoint == 0) {
//when direction = 1, it's a traversal of all points with O(n)
//when direction = -1, the construction of convex hull began which is O(nlogn)
direction = direction * -1;
if (currentPoint == 0){
/****add code here*****/
}
}
currentPoint+= direction;
}
코드없이 명확하게 제 질문을 설명하기가 어렵습니다. currentPoint = 0
일 때 addpoint()
함수를 종료 할 수 있도록 몇 가지 코드를 추가하고 싶습니다. exit()
가 작동하지 않습니다. 프로그램 전체가 종료되고 이미 재생 된 애니메이션이 사라지기 때문입니다. 나는 그것에 대한 좋은 해결책을 생각할 수 없다. 그것에 대해 누구나 아이디어를 가지고 있는가?processing3을 사용하여 볼록한 선체 프로젝트를 만들고 있는데, 어쨌든 함수 (전체 프로그램이 아님)를 종료 할 수 있는지 누군가가 말해 줄 수 있습니까?
추가 할'반환,'상기 보지 않고 (작동된다 ..that 나머지 구현). – nullpointer
more info http://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html – nullpointer
앞으로는 전체 프로그램 대신 [mcve]를 게시하십시오. 간단한 프로그램은 디버그하는 것이 훨씬 쉽습니다. 또한 올바른 형식을 사용하십시오. 코드를 읽기가 매우 어렵습니다. –