static void Main(string[] args)
        {
            // Origin Point
            Console.WriteLine(Point3D.Origin);
            Console.WriteLine();

            // Distance Between Two Points
            Point3D p1 = new Point3D(0, 2, 3);
            Point3D p2 = new Point3D(1, 4, 3);
            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine("Distance: {0}", Point.Distance(p1, p2));
            Console.WriteLine();

            // Save and Load Paths
            Path path1 = new Path();
            path1.AddPoint(3, 4, 5);
            path1.AddPoint(1, 1, 1);
            PathStorage.SavePath(path1, false);

            Path path2 = new Path();
            path2.AddPoint(6, 8, 6);
            path2.AddPoint(1, 2, 3);
            PathStorage.SavePath(path2, true);

            Console.WriteLine(PathStorage.LoadPath());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Problem 1 - Point3D
            
            Point3D p1 = new Point3D(1, 2, 3);
            Point3D p2 = new Point3D(5.35, 2.7, -3.29);
            Console.WriteLine();

            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine(Point3D.StartingPoint);
            Console.WriteLine();
            Console.WriteLine(new String('*', 20));
            Console.WriteLine();
            
            //Problem 2 - Distance Calculator

            double distance = DistanceCalculator.distance(p1, p2);
            Console.WriteLine(distance);
            Console.WriteLine();
            Console.WriteLine(new String('*', 20));
            Console.WriteLine();

            //Problem 3 - Paths

            Path path = new Path(p1, p2, Point3D.StartingPoint);
            Console.WriteLine("Save points {0} in path.", path);
            Storage.SaveFile("paths.txt", path);
            Path loadFile = Storage.LoadPath("paths.txt");
            Console.WriteLine("Load path: {0}", loadFile);
        }
Beispiel #3
0
        public static Path LoadPath(string file)
        {
            Path path = new Path();

            using (StreamReader sr = new StreamReader(file))
            {
                string entry = sr.ReadToEnd();

                string pattern = "{([\\d,.-]+), ([\\d,.-]+), ([\\d,.-]+)}";
                var rg = new Regex(pattern);
                var mathes = rg.Matches(entry);

                if (mathes.Count <= 0)
                {
                    throw new ArgumentException("Bad values in text file!");   
                }

                foreach (Match match in mathes)
                {
                    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 pt = new Point3D(x, y, z);
                    path.AddPoint(pt);
                }
            }
            return path;
        }
Beispiel #4
0
        // Save and load paths in 3D space from a text file
        public static void Main()
        {
            // Create 3 points in space
            Point3D p1 = new Point3D(2, 3, 4);
            Point3D p2 = new Point3D(5, 6, 7);
            Point3D p3 = new Point3D(8, 9, 0);

            // Create a path from the points
            Path3D pathSave = new Path3D(p1, p2, p3);

            // Print the path
            Console.WriteLine(@"Path in 3D space to save to file (...\...\path.txt):");
            pathSave.PrintPath();

            // Save the path to a file
            string file = @"...\...\path.txt";
            Path3dStorage.SavePathToFile(pathSave, file);

            // Load the path from the file
            Path3D pathLoad = Path3dStorage.LoadPathFromFile(file);

            // Print the loaded path
            Console.WriteLine();
            Console.WriteLine(@"Path in 3D space loaded from file (...\...\path.txt):");
            pathLoad.PrintPath();

            // Calculate the distance between two points in the 3D space.
            double p1p2 = Distance3D.CalcDistance(p1, p2);
            Console.WriteLine("\nDistance between p{0} and p{1}: {2:F2}", p1, p2, p1p2);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.WriteLine(Point3D.StartingPoint.ToString());

            Point3D rectA = new Point3D("A", 1.2, 3, 5.6);
            Point3D rectB = new Point3D("B", -1.2, 3, 5.6);
            Point3D rectC = new Point3D("C", 1.2, -3, 5.6);
            Point3D rectD = new Point3D("D", 1.2, 3, -5.6);

            Path3D path = new Path3D(rectA, rectB, rectC, rectD);
            Console.WriteLine(path.ToString());

            //for (int i = 0; i < path.Count; i++)
            //{
            //    Console.WriteLine(path[i]);
            //}

            Console.WriteLine(DistanceCalculator.CalculateDistance3D(rectA, rectD));

            //Storage tests
            Storage.SavePath(@"../../user_files/SavedPaths.txt",false, path);
            Storage.SavePath(@"../../user_files/SavedPaths.txt", true, path);

         var loadedList=   Storage.LoadPaths(@"../../user_files/SavedPaths.txt");
         loadedList.ForEach(p=>Console.WriteLine(p.ToString()));

        }
Beispiel #6
0
        static void Main()
        {
            Point3D first = new Point3D(2, 3, 4);
            Point3D second = new Point3D(5, 6, 7);

            Console.WriteLine(DistanceCalculator.CalculateDistance3D(first, second));
        }
        public static double CalculateDistance(Point3D point1, Point3D point2)
        {
            double result = Math.Sqrt(
                (Math.Pow((point1.X - point2.X), 2) + Math.Pow((point1.Y - point2.Y), 2) + Math.Pow((point1.Z - point2.Z), 2))
                );

            return result;
        }
Beispiel #8
0
        public static Point3D Deserialize(string pointStr){
            Regex rgx = new Regex(@"(.+?){(.+?),(.+?),(.+?)}");
            MatchCollection matches = rgx.Matches(pointStr);
                var g = (matches[0] as Match).Groups ;
                Point3D point = new Point3D(g[1].Value, double.Parse(g[2].Value), double.Parse(g[3].Value), double.Parse(g[4].Value));

                return point;
        }
 public static double CalculateDistance3D(Point3D firstPoint, Point3D secondPoint)
 {
     double distance = 0;
     distance = Math.Sqrt(Math.Pow(firstPoint.X - secondPoint.X, 2)
         + Math.Pow(firstPoint.Y - secondPoint.Y, 2)
         + Math.Pow(firstPoint.Z - secondPoint.Z, 2));
     return distance;
 }
 public static double CalculateDistance3D(Point3D firstPoint3D, Point3D secondPoint3D)
 {
     double distance = 0;
     distance = Math.Sqrt((firstPoint3D.X - secondPoint3D.X) * (firstPoint3D.X - secondPoint3D.X) +
         (firstPoint3D.Y - secondPoint3D.Y) * (firstPoint3D.Y - secondPoint3D.Y) +
         (firstPoint3D.Z - secondPoint3D.Z) * (firstPoint3D.Z - secondPoint3D.Z));
     return distance;
 }
Beispiel #11
0
        public static double CalcDistance(Point3D pA, Point3D pB)
        {
            if (pA.X == pB.X && pA.Y == pB.Y && pA.Z == pB.Z)
            {
                return 0;
            }

            double diffX = pA.X - pB.X;
            double diffY = pA.Y - pB.Y;
            double diffZ = pA.Z - pB.Z;
            double distance = Math.Sqrt((diffX * diffX) + (diffY * diffY) + (diffZ * diffZ));
            return distance;
        }
        /// <summary>
        /// Reads a list of lines which contain points in 3D space and adds them to a path.
        /// </summary>
        /// <param name="fileLines">The list of lines.</param>
        /// <returns>Returns the path as a list of points.</returns>
        private static Path3D ParsePath(List<string> fileLines)
        {
            Path3D path = new Path3D();

            // string.Format("({0}, {1}, {2})", this.X, this.Y, this.Z);
            foreach (var line in fileLines)
            {
                double[] coord = line.Split(Separators, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
                Point3D pt = new Point3D(coord[0], coord[1], coord[2]);
                path.AddPoint(pt);
            }

            return path;
        }
Beispiel #13
0
        static void Main()
        {
            // first create 3 points
            Point3D p1 = new Point3D(1.3, 2.3, 3.1);
            Point3D p2 = new Point3D(4.2, 2.8, -5);
            Point3D p3 = new Point3D(1.1, 2.5, 11.7);

            // calculate distance between first two points
            Console.WriteLine("Distance between p1 and p2: {0}", CalcDistance.TwoPoints(p1, p2));

            // create two test paths and save them to two files
            Path testPath1 = new Path();
            testPath1.AddPoint(p1);
            testPath1.AddPoint(p2);
            testPath1.AddPoint(p3);
            PathStorage.SavePath(testPath1, "SavedTestPath1");

            Path testPath2 = new Path();
            testPath2.AddPoint(p3);
            testPath2.AddPoint(p2);
            testPath2.AddPoint(p1);
            PathStorage.SavePath(testPath2, "SavedTestPath2");

            // create third path and load its points from file of first path
            Path testPath3 = new Path();
            testPath3 = PathStorage.LoadPath("SavedTestPath1");

            // save third path to SavedTestPath3.txt
            PathStorage.SavePath(testPath3, "SavedTestPath3");

            // SavedTestPath3.txt should be the same as SavedTestPath1.txt

            try
            {
                testPath3 = PathStorage.LoadPath("NonExistentFile");
            }
            catch (Exception ex)
            {
                Console.WriteLine("An expected error occurred. Error message:\n{0}", ex.Message);
            }
        }
        public static Path LoadPath(string filePath)
        {
            Path path = new Path();

            using (StreamReader sr = new StreamReader(filePath))
            {
                int lineNumber = 0;
                while (!sr.EndOfStream)
                {
                    lineNumber++;
                    string currentText = sr.ReadLine();
                    string[] coordinatesStr = currentText.Split(new char[] { ' ', '{', '}', ',' }, StringSplitOptions.RemoveEmptyEntries);

                    double[] coordinates = new double[1];

                    try
                    {
                        coordinates = coordinatesStr.Select(x => double.Parse(x)).ToArray();
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException("Invalid file format", ex);
                    }

                    if (coordinates.Length != 3)
                    {
                        throw new ArgumentException(
                            string.Format("Invalid file format. There are expected coordinates in three directions. Line number: {0}", lineNumber)
                            );

                    }

                    Point3D point = new Point3D(coordinates[0], coordinates[1], coordinates[2]);
                    path.AddPoint(point);
                }
            }

            return path;
        }
Beispiel #15
0
        public static Path LoadPath(string fileName)
        {
            Path loadedPath = new Path();
            if (!File.Exists(String.Format(@"..\..\{0}.txt", fileName)))
            {
                throw new ArgumentException("File to load path from does not exist!");
            }

            using (StreamReader input = new StreamReader(String.Format(@"..\..\{0}.txt", fileName)))
            {
                string[] loadedPoints = input.ReadLine().Split(new char[] {'*'},StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < loadedPoints.Length; i++)
                {
                    string[] loadedPoint = loadedPoints[i].Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Substring(1)).ToArray();
                    Point3D currentPoint = new Point3D();
                    currentPoint.X = double.Parse(loadedPoint[0]);
                    currentPoint.Y = double.Parse(loadedPoint[1]);
                    currentPoint.Z = double.Parse(loadedPoint[2]);
                    loadedPath.AddPoint(currentPoint);
                }
            }

            return loadedPath;
        }
        static void Main()
        {
            // test point3D
            Point3D point = new Point3D(5.5, 2.1, 100);
            Console.WriteLine("Point3D test:");
            Console.WriteLine(point);
            Console.WriteLine();

            // test zero point
            Console.WriteLine("Zero point test:");
            Console.WriteLine(Point3D.ZeroPoint);
            Console.WriteLine();

            //test calculate the distance
            Console.WriteLine("Calculate distance tests:");
            Point3D point1 = new Point3D(-7, -4, 3);
            Console.WriteLine("Point1: {0}", point1);
            Point3D point2 = new Point3D(17, 6, 2.5);
            Console.WriteLine("Point2: {0}", point2);
            double distance = Space3D.CalculateDistance(point1, point2);
            Console.WriteLine("Distance between {0}, {1} = {2}", point1, point2, distance);
            Console.WriteLine();
            Point3D point3 = new Point3D(1, 1, 1);
            distance = Space3D.CalculateDistance(Point3D.ZeroPoint, point3);
            Console.WriteLine("Distance between zero point and point {0} = {1}", point3, distance);
            Console.WriteLine();

            // test path
            Console.WriteLine("Test path:");
            point = new Point3D(1, 2, 3);
            Path path = new Path(point);
            Console.WriteLine("Path is created with statrt point {0}", point);
            point = new Point3D(4, 5, 6);
            path.AddPoint(point);
            Console.WriteLine("Point {0} is added to the path", point);
            Point3D[] points = new Point3D[2];
            points[0] = new Point3D(10, 20, 30);
            points[1] = new Point3D(0.1, 200, 300.5);
            Console.WriteLine("Points {0} and {1} are added to the path", points[0], points[1]);
            path.AddPoints(points);
            Console.WriteLine("Path: ");
            Console.WriteLine(path);
            Console.WriteLine();

            List<Point3D> test = path.Points;
            point = new Point3D(100, 200, 300);
            test[0] = point;
            Console.WriteLine("Path: ");
            Console.WriteLine(path);
            Console.WriteLine();

            // test  PathStorage
            Console.WriteLine("Test PathStorage:");
            string filePath = @"..\..\PathStorageTest.txt";
            PathStorage.SavePath(path, filePath);
            Console.WriteLine("The path is stored to file {0}", filePath);
            Path pathReaded = PathStorage.LoadPath(filePath);
            Console.WriteLine("The path is readed from file {0}", filePath);
            Console.WriteLine("Path readed from file: ");
            Console.WriteLine(pathReaded);
            path.Clear();
            // test clear path
            Console.WriteLine("The first created path is cleared");
            Console.WriteLine(path);
        }
 public static double Calculate(Point3D p, Point3D q)
 {
     return Math.Sqrt(Math.Pow((p.X - q.X), 2) + Math.Pow((p.Y - q.Y), 2) + Math.Pow((p.Z - q.Z), 2));
 }
Beispiel #18
0
 static double CalculateDistance(Point3D p1, Point3D p2)
 {
     return(Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y) + (p1.Z - p2.Z) * (p1.Z - p2.Z)));
 }
Beispiel #19
0
        // Methods
        public static double Distance(Point3D p1, Point3D p2)
        {
            double distance = Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Z, 2) + Math.Pow(p2.Z - p1.Z, 2));

            return distance;
        }
Beispiel #20
0
 public void AddPoint(Point3D p)
 {
     this.pathPoints.Add(p);
 }
 public static double distance(Point3D pointOne, Point3D pointTwo)
 {
     double distance;
     distance = Math.Sqrt(Math.Pow((pointTwo.X - pointOne.X), (double)2) + Math.Pow((pointTwo.Y - pointOne.Y), (double)2) + Math.Pow((pointTwo.Z - pointOne.Z), (double)2));
     return distance;
 }
 static Point3D()
 {
     zeroPoint = new Point3D(0, 0, 0);
 }
Beispiel #23
0
 static Point3D()
 {
     startingPoint = new Point3D("Center", 0, 0, 0);
 }
Beispiel #24
0
 static Point3D()
 {
     startPoint = new Point3D(0, 0, 0);
 }
Beispiel #25
0
 public void Add(Point3D point)
 {
     this.Paths.Add(point);
 }
Beispiel #26
0
 public void AddPoint(Point3D point)
 {
     this.Path.Add(point);
 }
 public Path(Point3D startPoint)
     : this()
 {
     this.points.Add(startPoint);
 }
Beispiel #28
0
 //Method for adding point in the List
 public void AddPoint(Point3D point)
 {
     this.pts.Add(point);
 }
 public void AddPoint(Point3D point)
 {
     points.Add(point);
 }
Beispiel #30
0
 // Constructors
 static Point3D()
 {
     Number = 0;
     origin = new Point3D(0, 0, 0);
     origin.Index = 0;
 }
 public void DeletePoint(Point3D point)
 {
     points.Remove(point);
 }