public static void Main() { // The first three problems are in this project Point3D point = new Point3D(5.4m, 6.6m, 3.1m); Console.WriteLine(point); Point3D anotherPoint = new Point3D(1m, 5.78m, -2.75m); Console.WriteLine(anotherPoint); Console.WriteLine("{0:F3}", DistanceCalculation.CalculateDistance(point, anotherPoint)); Point3D basePoint = Point3D.StartingPoint; Console.WriteLine(basePoint); Path3D listOfPoints = new Path3D(); listOfPoints.AddPoint(point); listOfPoints.AddPoint(basePoint); listOfPoints.AddPoint(anotherPoint); Storage.SavePath(listOfPoints); }
public static Path3D LoadPaths(string fileName) { try { string input = File.ReadAllText(fileName); string pattern = @"X=(.+?), Y=(.+?), Z=(.+?)"; var reg = new Regex(pattern); var matchs = reg.Matches(input); Path3D path = new Path3D(); foreach (Match match in matchs) { double x = double.Parse(match.Groups[1].Value); double y = double.Parse(match.Groups[2].Value); double z = double.Parse(match.Groups[3].Value); Point3D point = new Point3D(x, y, z); path.AddPoint(point); } return path; } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex.InnerException; } }
static void Main(string[] args) { //Probmel 1 Console.WriteLine(new string('-', 10)); Console.WriteLine("Problem 1 test:"); Console.WriteLine(new string('-', 10)); Point3D p1 = new Point3D(1, 2, 34); Console.WriteLine(p1); Console.WriteLine(Point3D.StartingPoint); Point3D p2 = new Point3D(23, 231, 4); //Problem 2 Console.WriteLine(new string('-', 10)); Console.WriteLine("Problem 2 test:"); Console.WriteLine(new string('-', 10)); Console.WriteLine(DistanceCalculator.CalcDistance(p1, p2)); //Problem 3 Console.WriteLine(new string('-', 10)); Console.WriteLine("Problem 3 test:"); Console.WriteLine(new string('-', 10)); List <Point3D> listOfPoints = new List <Point3D> { p1, p2 }; Path3D path = new Path3D(listOfPoints); path.AddPoint(new Point3D(2, 234, 4)); Console.WriteLine(path); Storage.Write(path); Storage.Read(); }
public static Path3D LoadPathOfFile(string fileName) { Path3D path = new Path3D(); using (StreamReader reader = new StreamReader(fileName)) { string input = reader.ReadToEnd(); string pattern = "{([\\d,.]+), ([\\d,.]+), ([\\d,.]+)}"; var reg = new Regex(pattern); var matches = reg.Matches(input); if (matches.Count <= 0) { throw new ApplicationException("Invalid data in file " + fileName); } foreach (Match match in matches) { double x = double.Parse(match.Groups[1].Value); double y = double.Parse(match.Groups[2].Value); double z = double.Parse(match.Groups[3].Value); Point3D p = new Point3D(x, y, z); path.AddPoint(p); } } return(path); }
public static Path3D LoadPathOfFile(string fileName) { Path3D path = new Path3D(); using (StreamReader sr = new StreamReader(fileName)) { string input = sr.ReadToEnd(); string pattern = "{([\\d,.]+), ([\\d,.]+), ([\\d,.]+)}"; var reg = new Regex(pattern); var matches = reg.Matches(input); if (matches.Count <= 0) { throw new ApplicationException("Invalid data in file " + fileName); } foreach (Match match in matches) { double x = double.Parse(match.Groups[1].Value); double y = double.Parse(match.Groups[2].Value); double z = double.Parse(match.Groups[3].Value); Point3D p = new Point3D(x, y, z); path.AddPoint(p); } } return path; }
public static Path3D LoadPaths(string fileName) { try { string input = File.ReadAllText(fileName); string pattern = @"X=(.+?), Y=(.+?), Z=(.+?)"; var reg = new Regex(pattern); var matchs = reg.Matches(input); Path3D path = new Path3D(); foreach (Match match in matchs) { double x = double.Parse(match.Groups[1].Value); double y = double.Parse(match.Groups[2].Value); double z = double.Parse(match.Groups[3].Value); Point3D point = new Point3D(x, y, z); path.AddPoint(point); } return(path); } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex.InnerException; } }