示例#1
0
        public static Path LoadPath(string name)
        {
            Path filePath = new Path();

            string fullPath = Text.Path.Combine("..\\..\\Paths", String.Format("{0}.txt", name.Trim()));

            try
            {
                var reader = new Text.StreamReader(fullPath);
                using (reader)
                {
                    var points = reader.ReadToEnd().Split(new string[] {"-"}, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var point in points)
                    {
                        var coordinates = point.Trim('{').Trim('}').Split(new char[] {' ', ','}, StringSplitOptions.RemoveEmptyEntries).ToArray();

                        var newPoint = new Point3D(double.Parse(coordinates[0]), double.Parse(coordinates[1]), double.Parse(coordinates[2]));

                        filePath.AddPoint(newPoint);
                    }
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e.Message);
                return null;
            }

            return filePath;
        }
示例#2
0
        public static Path LoadLastPathFromFile()
        {
            Path newSequence = new Path();
            using (StreamReader reader = new StreamReader(@"../../SavedPath.txt"))
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        if ((char.IsDigit(line[0])))
                        {
                            string[] components = line.Split();
                            Point3D newPoint = new Point3D(int.Parse(components[1]), int.Parse(components[2]), int.Parse(components[3]));
                            newSequence.AddPointToSequence(newPoint);
                        }
                    }
                    line = reader.ReadLine();
                }
            }

            if (newSequence.SequenceOfPoints.Count == 0)
            {
                throw new FileLoadException("The file you are trying to load is empty!");
            }

            return newSequence;
        }
示例#3
0
        static void Main()
        {
            Point3D myPoint = new Point3D(1, 2, 3);
            Console.WriteLine("The ToString() overload: {0}", myPoint);
            Console.WriteLine();

            Console.WriteLine("The static point 0: {0}", Point3D.CentrePoint);
            Console.WriteLine();

            Point3D myOtherPoint = new Point3D(3, 2, 1);
            double pointsDistance = CalculateDistance.Distance(myPoint, myOtherPoint);
            Console.WriteLine("Calculated distance: {0}", pointsDistance);
            Console.WriteLine();

            Path route = new Path();
            route.AddPoint(Point3D.CentrePoint);
            route.AddPoint(myPoint);
            route.AddPoint(myOtherPoint);
            route.AddPoint(new Point3D(1.1, 2.2, 3.82743658793465));
            Console.WriteLine("One of the points in the path: {0}", route.PointsPath[1]);
            Console.WriteLine();

            PathStorage.SavePath(route, "../../test.txt");

            Path loadedRoute = PathStorage.LoadPath("../../test.txt");
            Console.WriteLine("Print path loaded from file");
            foreach (var point in loadedRoute.PointsPath)
            {
                Console.WriteLine(point);
            }
        }
        public static double CalculateDistance(Point3D a, Point3D b)
        {
            double distance = Math.Sqrt(
                ((a.X - b.X) * (a.X - b.X)) +
                ((a.Y - b.Y) * (a.Y - b.Y)) +
                ((a.Z - b.Z) * (a.Z - b.Z)));

            return distance;
        }
        public static double CalcDistance(Point3D first, Point3D second)
        {
            double distance = 0;
            double deltaX = second.X - first.X;
            double deltaY = second.Y - first.Y;
            double deltaZ = second.Z - first.Z;

            distance = Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));

            return distance;
        }
        static void Main()
        {
            Point3D p1 = new Point3D(1, 2, 3);
            Point3D p2 = new Point3D(4, 5, 6);

            Console.WriteLine("Distance between ({0}) and ({1}) = {2}", p1, p2, Distance.Calculate(p1, p2));

            Path path = new Path();

            path.AddPoint(p1);
            path.AddPoint(p2);

            PathStorage.Save(path, @"../../pointList.txt");
            PathStorage.Load(@"../../pointList.txt");
        }
        public static Path LoadPathFromFile(string path)
        {
            StreamReader reader = new StreamReader(path);
            Path curentPath = new Path();

            using (reader)
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] temp = line.Split(' ');
                    Point3D point = new Point3D(int.Parse(temp[0]), int.Parse(temp[1]), int.Parse(temp[2]));
                    curentPath.AddPointToPath(point);

                    line = reader.ReadLine();
                }
            }
            return curentPath;
        }
        public static Path LoadPathFromFile(string fileName)
        {
            string regex = @"X: (?<x>-?\d*\.?\d+([eE][-+]?\d+)?); Y: (?<y>-?\d*\.?\d+([eE][-+]?\d+)?); Z: (?<z>-?\d*\.?\d+([eE][-+]?\d+)?)";
            Path path = new Path();
            StreamReader reader = new StreamReader(fileName, Encoding.UTF8);

            using (reader)
            {
                while (!reader.EndOfStream)
                {
                    Match match = Regex.Match(reader.ReadLine(), regex);
                    double x = double.Parse(match.Groups["x"].Value);
                    double y = double.Parse(match.Groups["y"].Value);
                    double z = double.Parse(match.Groups["z"].Value);
                    Point3D point = new Point3D(x, y, z);
                    path.AddPoint(point);
                }
            }
            return path;
        }
        public static void Main()
        {
            Point3D a = new Point3D(2.26, 10.8, -5);
            Console.WriteLine("Point A {0}", a);

            Console.WriteLine("Origin {0}", Point3D.Origin);

            Point3D b = new Point3D(2, 8, -1);
            Console.WriteLine("Point B {0}", b);

            Console.WriteLine("The distance between A and B is {0}", Distance.CalculateDistance(a, b));

            Path path = new Path(Point3D.Origin, a, b, a, b);
            path.AddPoint(Point3D.Origin);
            path.AddPoint(new Point3D(-9.99, -8, 0));
            Console.WriteLine("The path is:\n{0}", path);

            PathStorage.SavePathToFile(@"..\..\path.txt", path);

            Path loadedPath = PathStorage.LoadPathFromFile(@"..\..\path.txt");
        }
        public static void Load(string filePath)
        {
            using (StreamReader reader = new StreamReader(filePath))
            {
                string line = reader.ReadLine();

                while (line != null)
                {
                    var readLine = reader.ReadLine().Split(new char[] {' ', ','}, StringSplitOptions.RemoveEmptyEntries);

                    double x = double.Parse(readLine[0]);
                    double y = double.Parse(readLine[1]);
                    double z = double.Parse(readLine[2]);

                    Point3D newPoint = new Point3D(x, y, z);

                    path.AddPoint(newPoint);

                    line = reader.ReadLine();
                }
            }
        }
示例#11
0
 public static Path LoadPath(string fileAddress)
 {
     Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
     Path loaded = new Path();
     StreamReader reader = new StreamReader(fileAddress);
     using (reader)
     {
         string line = reader.ReadLine();
         while (line != null)
         {
             line = line.Substring(6, (line.Length - 7));
             string[] coordinates = line.Split(new char[] {' ', ','},
                 StringSplitOptions.RemoveEmptyEntries);
             double x = double.Parse(coordinates[0]);
             double y = double.Parse(coordinates[1]);
             double z = double.Parse(coordinates[2]);
             Point3D nextPoint = new Point3D(x, y, z);
             loaded.AddPoint(nextPoint);
             line = reader.ReadLine();
         }
     }
     return loaded;
 }
示例#12
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Console.WriteLine("Creating Points");
            Console.WriteLine(new string('-', 30));
            
            var firstPoint = new Point3D(2.3, 5, 0);
            Console.WriteLine("First point: {0}", firstPoint);
            
            var zeroPoint = Point3D.ZeroPoint;
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Zero point: {0}", zeroPoint);

            var distance = PointsDistance.CalculateDistance(firstPoint, zeroPoint);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Distance between the points: {0:F2} ", distance);

            var path = new Path();
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Creating path.");

            path.AddPoint(firstPoint);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Adding first point.");

            path.AddPoint(zeroPoint);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Adding zero point.");

            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Path: {0}", path.ToString());

            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Total points in path: {0}", path.Count);

            path.RemovePoint(zeroPoint);
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Removing zero point.");

            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Path: {0}", path.ToString());

            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Total points in path: {0}", path.Count);

            path.Clear();
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Clearing path.");

            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Total points in path: {0}", path.Count);

            path.AddPoint(firstPoint);
            path.AddPoint(zeroPoint);
            PathStorage.SavePath(path, "input");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Saving path in a text file.");

            PathStorage.LoadPath("input");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Loading path from a text file.");

            
        }
示例#13
0
 public void Remove(Point3D point)
 {
     this.SequenceOfPoints.Remove(point);
 }
示例#14
0
 public void AddPointToSequence(Point3D point)
 {
     this.SequenceOfPoints.Add(point);
 }
示例#15
0
        public static double CalculateDistance(Point3D pointOne, Point3D pointTwo)
        {
            double result = Math.Sqrt(Math.Pow(pointTwo.X - pointOne.X, 2) + Math.Pow(pointTwo.Y - pointOne.Y, 2) + Math.Pow(pointTwo.Z - pointOne.Z, 2));

            return(result);
        }
 public static double Calculate(Point3D p1, Point3D p2)
 {
     return Math.Sqrt(Math.Pow((p1.X - p2.X), 2) + Math.Pow((p1.Y - p2.Y), 2) + Math.Pow((p1.Z - p2.Z), 2));
 }
示例#17
0
 public void AddPoint(Point3D newPoint)
 {
     pointsPath.Add(newPoint);
 }
示例#18
0
 public void RemovePoint(Point3D point)
 {
     this.points.Remove(point);
 }
 public static double Distance(Point3D a, Point3D b)
 {
     return Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)
         + Math.Pow(a.Z - b.Z, 2));
 }
示例#20
0
 public void RemovePoint(Point3D point)
 {
     this.PointsSequence.Remove(point);
 }
示例#21
0
        //method for calculating distance
        public static decimal CalculateDistance(Point3D firstPoint, Point3D secondPoint)
        {
            decimal distance = (decimal)Math.Sqrt(((firstPoint.X - secondPoint.X) * (firstPoint.X - secondPoint.X)) + ((firstPoint.Y - secondPoint.Y) * (firstPoint.Y - secondPoint.Y)) + ((firstPoint.Z - secondPoint.Z) * (firstPoint.Z - secondPoint.Z)));

            return distance;
        }
 public void AddPoint(Point3D point)
 {
     this.points.Add(point);
 }
示例#23
0
 //methods
 public void AddPoint(Point3D point)
 {
     this.PointsSequence.Add(point);
 }