public static List<double[]> lineSliceAlong(List<double[]> line, double startDist, double stopDist){double travelled = 0;double overshot = 0;int origCoordsLength = line.Count;List<double[]> slice = new List<double[]>();for (int i = 0; i < line.Count; i++){if (startDist >= travelled && i == line.Count - 1) break;else if (travelled > startDist && slice.Count == 0){overshot = startDist - travelled;if (overshot == 0){slice.Add(line[i]);return slice;}Vector3 point1 = new Vector3((float)line[i][0], (float)line[i][1], (float)line[i][2]);Vector3 point2 = new Vector3((float)line[i - 1][0], (float)line[i - 1][1], (float)line[i - 1][2]);Vector3 direction = Vector3.Normalize(point1 - point2);Vector3 moveP = point1 + direction * (float)overshot;slice.Add(new double[] { moveP.X, moveP.Y, moveP.Z });slice.Add(new double[] { moveP.X, moveP.Y, moveP.Z });}if (travelled >= stopDist){overshot = stopDist - travelled;if (overshot == 0){slice.Add(line[i]);return slice;}Vector3 point1 = new Vector3((float)line[i][0], (float)line[i][1], (float)line[i][2]);Vector3 point2 = new Vector3((float)line[i - 1][0], (float)line[i - 1][1], (float)line[i - 1][2]);Vector3 direction = Vector3.Normalize(point1 - point2);Vector3 moveP = point1 + direction * (float)overshot;slice.Add(new double[] { moveP.X, moveP.Y, moveP.Z });return slice;}if (travelled >= startDist){slice.Add(line[i]);}if (i == line.Count - 1){return slice;}List<double[]> tempLine = new List<double[]> { line[i], line[i + 1] };travelled += LineLength(tempLine);}if (travelled < startDist && line.Count == origCoordsLength){throw new Exception("Start position is beyond line");}double[] last = line[line.Count - 1];var temp = new List<double[]> { last, last };return temp;}public static List<double[]> lineChunck(List<double[]> line, double segmentLength, bool onlySegementPoint = false){List<double[]> result = new List<double[]>();double lineLength = LineLength(line);if (segmentLength <= 0){throw new Exception("segmentLength must be greater than 0");}if (lineLength <= segmentLength) return line;double numberOfSegments = lineLength / segmentLength;if ((int)numberOfSegments != numberOfSegments){numberOfSegments = Math.Floor(numberOfSegments) + 1;}for (int i = 0; i < numberOfSegments; i++){var outLine = lineSliceAlong(line, segmentLength * i, segmentLength * (i + 1));if (onlySegementPoint){result.Add(outLine.First());result.Add(outLine.Last());}else{for (int j = 0; j < outLine.Count; j++){var v = outLine[j];result.Add(v);}}}return distinctPoints(result);}public static List<double[]> distinctPoints(List<double[]> triplets){return triplets.Distinct(new TripletComparer()).ToList();}private class TripletComparer : IEqualityComparer<double[]>{public bool Equals(double[] x, double[] y){if (x.Length != y.Length) return false;for (int i = 0; i < x.Length; i++){if (x[i] != y[i]) return false;}return true;}public int GetHashCode(double[] obj){unchecked {int hash = 17;foreach (var val in obj){hash = hash * 23 + val.GetHashCode();}return hash;}}}