static void Main(string[] args) { Point3D p1 = new Point3D(2, 3, 8); Console.WriteLine("Problem 1. Point3D"); Console.WriteLine(p1); Console.WriteLine(Point3D.StartingPoint); Console.WriteLine(); Console.WriteLine("Problem 2. Distance Calculator"); Point3D p = new Point3D(-7, -4, 3); Console.WriteLine(p); Point3D q = new Point3D(17, 6, 2.5); Console.WriteLine(q); Console.WriteLine(); Console.WriteLine(DistanceCalculator.CalculateDistance(p, q)); Console.WriteLine(); Console.WriteLine("Write to File: "); _03_Paths path = new _03_Paths(p, q, Point3D.StartingPoint); Console.WriteLine(path); path.WriteToFile("../../points.txt"); Console.WriteLine("Read From File: "); _03_Paths pathFromFile = _03_Paths.ReadFromFile("../../points.txt"); Console.WriteLine(pathFromFile); }
public static _03_Paths ReadFromFile(string fileName) { string text = File.ReadAllText(fileName); string pattern = @"X = (.*?), Y = (.*?), Z = (.*?)\)"; Regex rgx = new Regex(pattern); MatchCollection matches = rgx.Matches(text); _03_Paths path = new _03_Paths(); for (int i = 0; i < matches.Count; i++) { double x = Double.Parse(matches[i].Groups[1].Value); double y = Double.Parse(matches[i].Groups[2].Value); double z = Double.Parse(matches[i].Groups[3].Value); Point3D point = new Point3D(x, y, z); path.Points.Add(point); } return path; }
public static _03_Paths ReadFromFile(string fileName) { string text = File.ReadAllText(fileName); string pattern = @"X = (.*?), Y = (.*?), Z = (.*?)\)"; Regex rgx = new Regex(pattern); MatchCollection matches = rgx.Matches(text); _03_Paths path = new _03_Paths(); for (int i = 0; i < matches.Count; i++) { double x = Double.Parse(matches[i].Groups[1].Value); double y = Double.Parse(matches[i].Groups[2].Value); double z = Double.Parse(matches[i].Groups[3].Value); Point3D point = new Point3D(x, y, z); path.Points.Add(point); } return(path); }