public static double CalculateTheDistanceTwoPoints(Point3D a, Point3D b) { double result = 0; double processX = Math.Pow((a.PointX - b.PointX), 2); double processY = Math.Pow((a.PointY - b.PointY), 2); double processZ = Math.Pow((a.PointZ - b.PointZ), 2); result = Math.Sqrt(processX + processY + processZ); return result; }
public static double CalculateTheDistanceFromPath(Path3D inPath) { double result = 0; int counter = 0; Point3D first = new Point3D(); Point3D second = new Point3D(); foreach (var item in inPath.PointsList3D) { if (counter == 0) { first = item; counter++; continue; } second = item; result += DistanceCalculator.CalculateTheDistanceTwoPoints(first, second); first = second; } return result; }
public static List<Point3D> ExtractPointListFromTxt(string file) { string path = file; // Open the file to read from. using (StreamReader sr = File.OpenText(path)) { string s = ""; char delimeter = ','; List<Point3D> outPointsList = new List<Point3D>(); Point3D currPoint = new Point3D(0, 0, 0); Regex matchRegex = new Regex(@"([XYZ= ]+[-\d]*[\.\d,]*)+"); string replacePattern = @"[XYZ= ]+"; double currX; double currY; double currZ; // Convert text lines to Point3D parameters while ((s = sr.ReadLine()) != null) { Match myMatch = matchRegex.Match(s); string matched = myMatch.Groups[0].Value; string cleaned = Regex.Replace(matched, replacePattern, ""); string[] currNumbs = cleaned.Split(delimeter); currX = Convert.ToDouble(currNumbs[0]); currY = Convert.ToDouble(currNumbs[1]); currZ = Convert.ToDouble(currNumbs[2]); // Assign parameters to Point3D currPoint = new Point3D(currX, currY, currZ); // Add to Point3D List outPointsList.Add(currPoint); } return outPointsList; } }