java - Connect collection of points by finding neighborhood points -
i have swing application in have arraylist of points on image. want connect points such each point connected nearest neighbors.
like this:
so started this:
minuatiae.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; } }
manager.java
list<minutiae> minuatiaepoints = new arraylist<minutiae>(minutiae); for(int = 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++) // <- 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()); }
but connects 1 nearest point.
could me this? link or example code grateful.
you have 2 options:
once have minimum distance, have go @ list , connect minimum distance = min distance (therefore need find min. distance). , on second run if dist=min distance, draw line every time have equality.
the second option keep list of minimum distance points , go through list draw lines.
edit: updated add code second algortihm:
list<minutiae> minuatiaepoints = new arraylist<minutiae>(minutiae); for(int = 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); list<minutiae> mindistpoints = new arraylist<minutiae>(); for(int j = 0; j < minuatiaepoints.size(); j++) // <- 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; mindistpoints = new arraylist<minutiae>(); mindistpoints.add(testpt); } else if (dist = mindist) { mindistpoints.add(testpt); } } for(minutae p: mindistpoints){ g2d.drawline(mpoint.getx(), mpoint.gety(), p.getx(), p.gety()); } }
Comments
Post a Comment