Advertisement
Guest User

KalEl

a guest
Sep 22nd, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1.         public Point2D.Double getGeoMedian(Point2D.Double start) {
  2.             double cx=start.x, cy=start.y;
  3.             double lastcx,lastcy;
  4.             int cnt=0;
  5.             do {
  6.                 lastcx=cx;lastcy=cy;
  7.                 cx=0; cy=0;
  8.                 double totalWeight=0;
  9.                 for (int i=0; i<points.size(); ++i) {
  10.                     Point2D.Double pt=(Point2D.Double)points.get(i);
  11.                     double weight=1/pt.distance(lastcx,lastcy);
  12.                     cx+=pt.x*weight; cy+=pt.y*weight;
  13.                     totalWeight+=weight;
  14.                 }
  15.                 cx/=totalWeight; cy/=totalWeight;
  16.             } while ((Math.abs(cx-lastcx)>.5 || Math.abs(cy-lastcy)>.5) && cnt++<2500);
  17.             return new Point2D.Double(cx,cy);
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement