我有一个摇摆应用程序,其中我有一个图像上一些点的 ArrayList。现在我想连接这些点,使每个点都连接到它最近的邻居。
像这样:
所以我是这样开始的:
细枝末节.java
public class Minutiae {
private int x;
private int y;
public Minutiae(int x, int y){
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
管理器.java
List<Minutiae> minuatiaePoints = new ArrayList<Minutiae>(minutiae);
for(int i = 0; i<minuatiaePoints.size(); i++){
Minutiae mPoint = minuatiaePoints.get(i);
Minutiae minPoint = minuatiaePoints.get((i+1) % minuatiaePoints.size());
int minXDistance = minPoint.getX()-mPoint.getX();
int minYDistance = minPoint.getY()-mPoint.getY();
double minDist = Math.hypot(minXDistance, minYDistance);
for(int j = 0; j < minuatiaePoints.size(); j++) // <- you had i++ here!
{
if (i == j) {
continue;
}
Minutiae testPt = minuatiaePoints.get(j);
double dist = Math.hypot(mPoint.getX() - testPt.getX(), mPoint.getY() - testPt.getY());
if (dist < minDist)
{
minDist = dist;
minPoint = testPt;
}
}
g2D.drawLine(mPoint.getX(), mPoint.getY(), minPoint.getX(), minPoint.getY());
}
但它只连接到一个最近的点。
谁能帮我解决这个问题?任何链接或示例代码将不胜感激。