public static List <SketchStroke> Resample(List <SketchStroke> strokes, int n) { double totalLength = 0; foreach (SketchStroke stroke in strokes) { totalLength += SketchStrokeFeatureExtraction.PathLength(stroke); } double I = totalLength / (n - 1); double D = 0.0; List <SketchStroke> newStrokes = new List <SketchStroke>(); // Iterates through each stroke points in a list of strokes int pointCount = 0; foreach (SketchStroke stroke in strokes) { //Resamples point locations List <SketchPoint> points = stroke.Points; List <SketchPoint> newPoints = new List <SketchPoint>(); newPoints.Add(new SketchPoint(points[0].X, points[0].Y)); ++pointCount; bool isDone = false; for (int i = 1; i < points.Count; ++i) { double d = MathHelpers.EuclideanDistance(points[i - 1], points[i]); if (D + d >= I) { double qx = points[i - 1].X + ((I - D) / d) * (points[i].X - points[i - 1].X); double qy = points[i - 1].Y + ((I - D) / d) * (points[i].Y - points[i - 1].Y); if (pointCount < n - 1) { newPoints.Add(new SketchPoint(qx, qy)); ++pointCount; points.Insert(i, new SketchPoint(qx, qy)); D = 0.0; } else { isDone = true; } } else { D += d; } if (isDone) { break; } } D = 0.0; // Resamples time stamps List <long> timeStamp = stroke.TimeStamp; List <long> newTimeStamp = new List <long>(); int oldCount = timeStamp.Count; int newCount = newPoints.Count; for (int j = 0; j < newCount; ++j) { int index = (int)((double)j / newCount * oldCount); newTimeStamp.Add(timeStamp[index]); } SketchStroke newStroke = new SketchStroke(newPoints, newTimeStamp); newStrokes.Add(newStroke); } return(newStrokes); }