Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Point2D.Double getGeoMedian(Point2D.Double start) {
- double cx=start.x, cy=start.y;
- double lastcx,lastcy;
- int cnt=0;
- do {
- lastcx=cx;lastcy=cy;
- cx=0; cy=0;
- double totalWeight=0;
- for (int i=0; i<points.size(); ++i) {
- Point2D.Double pt=(Point2D.Double)points.get(i);
- double weight=1/pt.distance(lastcx,lastcy);
- cx+=pt.x*weight; cy+=pt.y*weight;
- totalWeight+=weight;
- }
- cx/=totalWeight; cy/=totalWeight;
- } while ((Math.abs(cx-lastcx)>.5 || Math.abs(cy-lastcy)>.5) && cnt++<2500);
- return new Point2D.Double(cx,cy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement