static void Main() { Point3D firstPoint = new Point3D(0.22, -12, 3.12); Console.WriteLine(firstPoint); }
public static Path3D LoadFromFile(string filePath, List<Point3D> points) { Path3D path = new Path3D(points); using (StreamReader reader = new StreamReader(filePath)) { string line = reader.ReadLine(); const string pointPattern = @"Path:\s+((?:Point\s*\((?:.*?),\s*(?:.*?),\s*(?:.*?)\)\s*)+)"; while (line != null) { Regex regex = new Regex(pointPattern); MatchCollection matches = regex.Matches(line); if (matches.Count == 3) { double x = double.Parse(matches[0].Groups[1].Value); double y = double.Parse(matches[1].Groups[2].Value); double z = double.Parse(matches[2].Groups[3].Value); Point3D point = new Point3D(x, y, z); path.AddPointToPath(point); } line = reader.ReadLine(); } } return path; }
static void Main() { Point3D x = new Point3D(0, 0, 0); Point3D y = new Point3D(0, 0, 2); Console.WriteLine(DistanceCalculator.CalculateDistance(x, y)); }
public static double CalculateDistance(Point3D x, Point3D y) { double firstDim = (x.pointX - y.pointX); double secondDim = (x.pointY - y.pointY); double thirdDim = (x.pointZ - y.pointZ); double calculation = Math.Sqrt( firstDim * firstDim + secondDim * secondDim + thirdDim * thirdDim); return calculation; }
public void AddPointToPath(Point3D point) { var currentPath = this.Path; currentPath.Add(point); this.Path = currentPath; }