0
私は、convexHullアルゴリズムを書くようにblindSearchメソッドを作成しています。それは正しく動作しません、そして内部ポイントを削除doesnt。私を助けてくれますか?アルゴリズムをコンパイルするのに役立つ
public Point pnt[] = new Point[1000000];
public Point temp[] = new Point[1000000];
private int count = 0;
private int pointCount = 0;
Point point1;
Point point2;
Point point3;
Point temp1;
Point temp2;
....
とblindSearch方法:
public void blindSearch()
{
if(pointCount<3)
{
if(pointCount == 1)
System.out.print("Done!");
else if(pointCount == 2)
{
point1 = pnt[0];
point2 = pnt[1];
draw2points(this.getGraphics());
}
}
for(int i = 0; i<pointCount - 2 ; i++)
{
for (int j = 1; j<pointCount - 1; j++)
{
for (int k = 2; k<pointCount ; k++)
{
Point p1 = pnt[i];
Point p2 = pnt[j];
Point p3 = pnt[k];
point1 = p1;
point2 = p2;
point3 = p3;
for(int m = 3; m <pointCount ; m++)
{
if(det(point1, point2, point3, p[m]))
{
remove(m);
}
}
}
}
}
for(int i = 0; i<count - 1;i++)
{
for(int j = 1; j<count; j++)
{
temp1 = temp[i];
temp2 = temp[j];
finaDrawing(this.getGraphics());
}
}
}
private void finaDrawing(Graphics graphics) {
graphics.drawLine(temp1.x, temp1.y, temp2.x, temp2.y);
}
public boolean det(Point pt1, Point pt2, Point pt3, Point pt4)
{
int det1 = pt1.x*(pt2.y-pt4.y)-pt2.x*(pt1.y-pt4.y)+pt4.x*(pt1.y-pt2.y);
int det2 = pt2.x*(pt3.y-pt4.y)-pt3.x*(pt2.y-pt4.y)+pt4.x*(pt2.y-pt3.y);
int det3 = pt3.x*(pt1.y-pt4.y)-pt1.x*(pt3.y-pt4.y)+pt4.x*(pt3.y-pt1.y);
if (det1>0 && det2>0 && det3>0)
return true;
else
return false;
}
public void remove(int n)
{
for(int i = 0; i<count; i++)
{
if(temp[i] == pnt[n])
{
for(int j = i+1;j<count; j++)
{
temp[j-1] = temp[j];
}
count--;
}
}
}
私はそれを行いましたが、変更はありませんでした –