, double y0s, double x1, double y1) {{x=
(x1 * pow (x0, 2)-y1 * y0s * x0 + y1 * y0 * x0 + x0 * pow (y0s, 2)-x0 * y0 * y0s - 2 * x1 * x0s * x0-y1 * y0 * x0s + y1 * y0s * x0s + x0s * pow (y0, 2) + x1 * pow (x0s, 2)-x0s * y0 * y0s) / (pow (y0, 2) + pow ( x0, 2) + pow (x0s, 2) - 2 * x0s * x0 + pow (y0s, 2) - 2 * y0 * y0s); y=
(2 * y0 * y1 * y0s + y1 * pow (y0, 2) + y0 * x1 * x0 + y1 * pow (y0s, 2) + pow (x0s, 2) * y0 + y0s * pow (x0, 2) - x0s * x0 * y0-y0s * x1 * x0-x0s * x0 * y0s-y0 * x1 * x0s + y0s * x1 * x0s) /
(pow (y0, 2) + pow (x0, 2) + pow (x0s, 2) - 2 * x0s * x0 + pow (y0s, 2) - 2 * y0 * y0s); out=sqrt (pow (x-x0, 2) + pow (y-y0, 2)); s=1; ((x0s-x0) * (x-x0) + (y0s-y0) * (y-y0 ) <0) {= - 1;
} out * s;
} catch (Exception e) {. out.println («error in G_Point.findProj»);
} 0;
}
6. Реалізація основного алгоритму.
void graphAction () {
/ / p-current position of mouse after clickdim=this.getSize (); dx=dim.width / 2 - image.getWidth (null) / 2; dy=dim.height / 2 -image.getHeight (null) / 2; p_tmp=this.toInitCord (p); pt=new Point (p_tmp.x - dx, p_tmp.y - dy);
bimage=new BufferedImage (image.getWidth (null), image.getHeight (null), BufferedImage.TYPE_INT_RGB);
/ / Draw the image on to the buffered imageD g2=bimage.createGraphics ();. drawImage (image, 0, 0, null);. dispose ();
defColour=- 1; (isPtInBImg (bimage, pt.x, pt.y)) {= bimage.getRGB (pt.x, pt.y);
} (defColour == - 1) {;
}
/ / checking for two points being initialized (isGraphOn2 == false) {= true; _p=new Point (p_tmp.x - dx, p_tmp.y - dy);;
} (g_p!=null) {_last=g_p;
} else {;
}
radius=1;
exit=false;
> packs=new ArrayList > ();
(radius > (); content=new ArrayList (); contentwrite=false;
pt_tmp=new Point (pt.x - radius, pt.y - radius); (int i=0; i <= 8 * radius - 1; i + +) {alpha=PI / 2 * (i / (2 * radius));
(isPtInBImg (bimage, pt_tmp.x, pt_tmp.y) && defColour == bimage.getRGB (pt_tmp.x, pt_tmp.y)) {. add (pt_tmp);=true ;
} if (contentwrite) {. add (content);=new ArrayList ();=false;
} _tmp=new Point (pt_tmp.x + (int) cos (alpha), pt_tmp.y + (int) sin (alpha));
}
(contentwrite) {
(! packs.isEmpty () && (packs.get (0). get (0). x == pt.x - radius && packs.get (0) . get (0). y == pt.y - radius)) {. addAll (0, packs.get (0));. set (0, content);=false;
} else {. add (content);=false;
}
}
(packs.size () == 2) {= false;;
} else {(packs.size () == 1 && packs.get (0). size () <= radius * 2 +1) {= false;; p>
} + +;