Here you can find the source of resample(Vector
public static void resample(Vector<Point2D> points, int n, Vector<Point2D> newPoints)
//package com.java2s; /* // www . j a v a 2 s .c o m * Authors: Caroline Appert (caroline.appert@lri.fr) * Copyright (c) Universite Paris-Sud XI, 2007. All Rights Reserved * Licensed under the GNU LGPL. For full terms see the file COPYING. */ import java.awt.geom.Point2D; import java.util.Vector; public class Main { public static void resample(Vector<Point2D> points, int n, Vector<Point2D> newPoints) { if (points.isEmpty()) return; Vector<Point2D> dstPts = new Vector<Point2D>(n); double segLength = pathLength(points) / (n - 1); double currentSegLength = 0; Vector<Point2D> srcPts = new Vector<Point2D>(points); dstPts.add((Point2D) srcPts.get(0).clone()); for (int i = 1; i < srcPts.size(); i++) { Point2D pt1 = srcPts.get(i - 1); Point2D pt2 = srcPts.get(i); double d = pt1.distance(pt2); if ((currentSegLength + d) >= segLength) { double qx = pt1.getX() + ((segLength - currentSegLength) / d) * (pt2.getX() - pt1.getX()); double qy = pt1.getY() + ((segLength - currentSegLength) / d) * (pt2.getY() - pt1.getY()); Point2D q = new Point2D.Double(qx, qy); dstPts.add(q); // append new point 'q' srcPts.add(i, q); // insert 'q' at position i in points s.t. // 'q' will be the next i currentSegLength = 0.0; } else { currentSegLength += d; } } // sometimes we fall a rounding-error short of adding the last point, so // add it if so if (dstPts.size() == (n - 1)) { dstPts.add((Point2D) srcPts.get(srcPts.size() - 1).clone()); } newPoints.clear(); newPoints.addAll(dstPts); } public static double pathLength(Vector<Point2D> points) { double d = 0; for (int i = 1; i < points.size(); i++) { d += points.get(i - 1).distance(points.get(i)); } return d; } }