내 프로그램 (내 프로그래밍 언어가 자바)에 문제가 있습니다. 객체의 Douglas-Peucker가 Points 배열이고 더글러스 - Peucker 알고리즘이 있습니다. 이 Point 배열에 직접 작업하고 싶습니다. 여기서 문제가 시작됩니다.void 메서드를 사용한 재귀?
protected Point[] coinImage;
// 내 생성자
public Peucker(Point [] tab) {
coinImage = new Point[tab.length];
for(int i = 0; i < coinImage.length; i++) {
coinImage[i] = new Point(tab[i].x, tab[i].y);
}
}
public Point[] algoDouglasPeucker() {
return douglasPeuckerAux(0,coinImage.length - 1);
}
public Point[] douglasPeuckerAux(int startIndex, int endIndex) {
double dmax = 0;
int index = 0;
for(int i = startIndex + 1; i < endIndex; i++) {
double distance = this.distancePointSegment(this.coinImage[i], this.coinImage[startIndex], this.coinImage[endIndex]);
if(distance > dmax) {
index = i;
dmax = distance;
}
} ***
if(dmax >= this.epsilon) {
Point[] recResult1 = douglasPeuckerAux(startIndex,index);
Point[] recResult2 = douglasPeuckerAux(index,endIndex);
Point [] result = this.unionTabPoint(recResult1, recResult2);
return result;
}
else {
return new Point[] { coinImage[0],coinImage[endIndex] };
}
}
*** my problem is here : both methods have a specific type of return : array of Point or I want to change this because I want to work directly on my attribut (coinImage).
이 무효 방법으로 변경하는 방법 :이 더글러스 Peucker 알고리즘? 도와주세요! 죄송합니다 나는 하나의 방법을 잊지 : 나는 또한이 방법의 유형을 변경하려면 :
public Point[] unionTabPoint(Point [] P1,Point [] P2) {
Point[] res = new Point[P1.length + P2.length];
for(int i = 0; i < P1.length;i++) {
res[i] = new Point(P1[i].x,P1[i].y);
}
int k = 0;
for(int j = P1.length; j < res.length; j++) {
res[j] = new Point(P2[k].x,P2[k].y);
k++;
}
return res;
}
그녀는 두 개의 배열하지만 특정 순서없이 노조를 반환합니다.
무엇 무효 방법 (PLS 더 명확히하지 않은 경우) 무엇을 찾고있다 희망? –
algoDouglasPeucker, DouglasPeuckerAux 및 unionTabPoint 메소드를 void 메소드로 변경하려고합니다. 나는 물건으로 일하고 싶지만 여기에서는 그렇지 않다. 그러나 void에서 세 가지 방법을 바꾸는 방법은 무엇입니까? 이 중 하나가 재귀이기 때문에 ... – afk