예제 #1
0
        public static Path Load(string source)
        {
            Path loadedPath = new Path();
            //initializing the PathList
            loadedPath.PathList = new List<Point3D>();
            char[] splittingChars = { '[', ']', ' ', ',' };
            using (StreamReader sourceFile = new StreamReader(source))
            {
                //read the first line of the file to check is it null
                string line = sourceFile.ReadLine();

                while (line != null)
                {
                    //splitting the data to get array of the points
                    string[] splittedString = line.Split(splittingChars, StringSplitOptions.RemoveEmptyEntries);
                    //creating int variables to parse the coordinates of the Point3D(int, int, int);
                    int coordX, coordY, coordZ;
                    //parsing the coordinates
                    coordX = int.Parse(splittedString[0]);
                    coordY = int.Parse(splittedString[1]);
                    coordZ = int.Parse(splittedString[2]);
                    //creating the current Point3D
                    Point3D currentPoint = new Point3D(coordX, coordY, coordZ);
                    //adding to the PathList
                    loadedPath.PathList.Add(currentPoint);
                    //reading next line
                    line = sourceFile.ReadLine();
                }
            }

            return loadedPath;
        }
예제 #2
0
        static void Main(string[] args)
        {
            //Creating a new instance of Point3D
            Point3D myFirstPoint = new Point3D(1, 2, 3);
            Point3D mySecondPoint = new Point3D(4, 5, 6);
            Point3D myThirdPoint = new Point3D(7, 8, 9);

            //Testing the overrite of ToString()
            Console.WriteLine("First point:");
            Console.WriteLine(myFirstPoint.ToString());

            //Testing the calculating of the distance
            Console.WriteLine("The distance between X,Y,Z is: {0}", DistanceBetweenThePoints.CalculateDistance(myFirstPoint, Point3D.Center));

            //Testing the static property Center
            Console.WriteLine();
            Console.WriteLine("Testing the center point: ");
            Console.WriteLine(Point3D.Center.ToString());

            //Testing the Path class
            Path myPath = new Path();

            //Intializing the PathList with new List<Point3d>()
            myPath.PathList = new List<Point3D>();

            //Adding some points:
            myPath.PathList.Add(myFirstPoint);
            myPath.PathList.Add(mySecondPoint);
            myPath.PathList.Add(myThirdPoint);
            myPath.PathList.Add(Point3D.Center);
            Console.WriteLine();
            Console.WriteLine("The Path Points are:");
            foreach (Point3D item in myPath.PathList)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();

            //Removing a point:
            myPath.PathList.Remove(Point3D.Center);
            Console.WriteLine("The Path Points after removing the center:");
            foreach (Point3D item in myPath.PathList)
            {
                Console.WriteLine(item.ToString());
            }

            //PathStorage - Loading
            Path loadedPath = PathStorage.Load("../../PathLoads.txt");

            //05. PathStorage - Saving
            PathStorage.Write(loadedPath, "../../PathSaves.txt");
        }
예제 #3
0
        public static double CalculateDistance(Point3D firstPoint, Point3D secondPoint)
        {
            double distance = Math.Sqrt(Math.Pow((firstPoint.coordX - secondPoint.coordX), 2) + Math.Pow((firstPoint.coordY - secondPoint.coordY), 2) + Math.Pow((firstPoint.coordZ - secondPoint.coordZ), 2));

            return distance;
        }