import java.util.*; import java.awt.*; public class Mametan { Vector root; Vector vect; ArrayImage img; public Mametan(ArrayImage img,Point edge) { root = new Vector(); vect = new Vector(); root.add(edge); this.img = img; } public Point getRoot(int i) { if( i < root.size()) { return root.get(i); } else { return null; } } private int kakudo(Point vec) { double x = vec.getX(); double y = vec.getY(); double s; s = Math.acos(x/Math.sqrt(x*x+y*y)); s=(s/3.14)*180.0; if (y<0) /* ƒÆ„ƒÎ‚ÌŽž */ s=360-s; return (int)Math.floor(s); } private int tikasa(Point gent,Point vect) { System.out.println( "tikasa"+ kakudo(gent)+" "+ kakudo(vect) ); int gen = kakudo(gent); int vec = kakudo(vect); if(gen < 90 && vec >270) { return gen-(360 - vec); } else if(vec < 90 && gen >270) { return (360-gen)-vec; } return gen - vec; } public void startDeconvolution() { Vector temp = null; // root.removeAllElements(); //vect.removeAllElements(); temp = nominateNext(); if(temp == null) { System.out.println("earch lost");return; } for(int i=0; temp != null &&temp.size()!= 0;i++) { if(i >5) { vect.add( new Point( (int)(root.get(i-1).getX() - root.get(i-3).getX()) , (int)(root.get(i-1).getY() - root.get(i-3).getY()) )); int num= 0; int sum= 360; int tp=0; for(int j=0; j< temp.size();j++) { tp = tikasa( vect.get(vect.size()-1),new Point ( (int)(temp.get(j).getX()-root.get(i-1).getX()), (int)(temp.get(j).getY()-root.get(i-1).getY()) ) ); if(tp <0){tp *=-1;} if(sum > tp){num = j; sum = tp; } } root.add(temp.get(num)); temp = nominateNext(); } else { root.add(temp.get(0)); temp = nominateNext(); } } } private Vector nominateNext() { Point st = root.get(root.size()-1); int x = (int)st.getX(); int y = (int)st.getY(); Vector next = new Vector(); if(img.index(x,y+1) > 0 && !havePoint(x,y+1)) {next.add(new Point(x ,y+1));} if(img.index(x+1,y) > 0 && !havePoint(x+1,y)) {next.add(new Point(x+1,y));} if(img.index(x+1,y+1) > 0 && !havePoint(x+1,y+1)) {next.add(new Point(x+1,y+1 ));} if(img.index(x+1,y-1) > 0 && !havePoint(x+1,y-1)) {next.add(new Point(x+1,y-1));} if(img.index(x-1,y-1) > 0 && !havePoint(x-1,y-1)) {next.add(new Point(x-1,y-1));} if(img.index(x-1,y) > 0 && !havePoint(x-1,y)) {next.add(new Point(x-1,y ));} if(img.index(x-1,y+1) > 0 && !havePoint(x-1,y+1)) {next.add(new Point(x-1,y+1));} if(img.index(x,y-1) > 0 && !havePoint(x,y-1)) {next.add(new Point(x ,y-1));} return next; } private boolean havePoint(int x,int y) { for(int i= 0;i