Пример #1
2
 public static Path LoadPath()
 {
     Path path = new Path();
     StreamReader reader = new StreamReader("..\\..\\paths.txt");
     using (reader)
     {
         string line = reader.ReadLine();
         while (line != null)
         {
             Point3D point = new Point3D();
             string[] pointsArray = line.Split(new char[] { '(', ')', ',' }, StringSplitOptions.RemoveEmptyEntries);
             point.X = int.Parse(pointsArray[0]);
             point.Y = int.Parse(pointsArray[1]);
             point.Z = int.Parse(pointsArray[2]);
             path.AddPoint(point);
             line = reader.ReadLine();
         }
     }
     return path;
 }
Пример #2
0
        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();
        }
Пример #3
0
 public void TestMethodParamConstructor_2()
 {
     Point3D point = new Point3D(-2.56f, 50.786f, -567.45123f);
     Assert.AreEqual(-2.56f, point.X);
     Assert.AreEqual(50.786f, point.Y);
     Assert.AreEqual(-567.45123f, point.Z);
 }
 public void TestMethodTwoPoints_2()
 {
     Point3D point1 = new Point3D(0, 5, 8);
     Point3D point2 = new Point3D(-1, -2, -4);
     float result = PointManipulations.PointsDistance(point1, point2);
     Assert.AreEqual(13.92839f, result);
 }
 public void TestMethodTwoPoints_1()
 {
     Point3D point1 = new Point3D(0, 5, 8);
     Point3D point2 = new Point3D(1, 2, 4);
     float result = PointManipulations.PointsDistance(point1, point2);
     Assert.AreEqual(5.09902f, result);
 }
Пример #6
0
        public static List<Path> LoadPaths(StreamReader file)
        {
            List<string> pathsFromFile = new List<string>();
            using (file)
            {
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    pathsFromFile.Add(line);
                }
            }

            List<Path> paths = new List<Path>();
            foreach (var path in pathsFromFile)
            {
                string[] points = path.Split('|');
                Point3D[] points3D = new Point3D[points.Length];
                for (int i = 0; i < points.Length; i++)
                {
                    points3D[i] = new Point3D(points[i]);
                }
                paths.Add(new Path(points3D));
            }

            return paths;
        }
Пример #7
0
 public void TestMethodEmptyConstructor()
 {
     Point3D point = new Point3D();
     Assert.AreEqual(0, point.X);
     Assert.AreEqual(0, point.Y);
     Assert.AreEqual(0, point.Z);
 }
Пример #8
0
 public void TestMethodParamConstructor_1()
 {
     Point3D point = new Point3D(3, -5, 0);
     Assert.AreEqual(3, point.X);
     Assert.AreEqual(-5, point.Y);
     Assert.AreEqual(0, point.Z);
 }
Пример #9
0
        /// <summary>
        /// Calculte distance between two points in 3D space
        /// </summary>
        /// <param name="aPoint">Point in 3D space</param>
        /// <param name="bPoint">Point in 3D space</param>
        /// <returns>Double: distance between two points</returns>
        public static double CalculteDistance(Point3D aPoint, Point3D bPoint)
        {
            double xDistance = (aPoint.X - bPoint.X);
            double yDistance = (aPoint.Y - bPoint.Y);
            double zDistance = (aPoint.Z - bPoint.Z);

            return Math.Sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance);
        }
Пример #10
0
 public void AddPoint(Point3D point)
 {
     if (point == null)
     {
         throw new ArgumentNullException("Point cannot be null");
     }
     this.Path.Add(point);
 }
Пример #11
0
        static void Main()
        {
            Point3D point1 = new Point3D(0, 5, 8);
            Point3D point2 = new Point3D(1, 2, 4);
            Point3D point3 = new Point3D(-3, 15, 60);
            Point3D[] points = { point1, point2, point3 };

            Path path = new Path(points);

            Point3D point4 = new Point3D(-10, 12, 80);
            Point3D point5 = new Point3D(11, 12, 5);
            Point3D point6 = new Point3D(-33, 155, 26);
            Point3D[] points1 = { point4, point5, point6 };

            Path path1 = new Path(points1);
            Console.WriteLine(path.Distance);

            foreach (var point in path.Points)
            {
                Console.WriteLine(point);
            }

            string filePath = @"..\..\..\TxtFiles\4thTask.txt";
            StreamWriter fileWrite = new StreamWriter(filePath, false, Encoding.GetEncoding(1251));
            using (fileWrite)
            {
                PathStorage.SavePath(path, fileWrite);
                PathStorage.SavePath(path1, fileWrite);
            }

            StreamReader fileRead = new StreamReader(filePath, Encoding.GetEncoding(1251));
            List<Path> readedPaths = PathStorage.LoadPaths(fileRead);
            foreach (var readedPath in readedPaths)
            {
                for (var i = 0; i < readedPath.Points.Length; i++)
                {
                    Console.Write(readedPath.Points[i]);
                }
                Console.WriteLine();
            }
        }
Пример #12
0
        static void Main()
        {
            ////Create point
            Point3D point = new Point3D(1, 2, 3);
            Point3D secondPoint = new Point3D(2, 3, 4);

            //print point
            Console.WriteLine(point);
            Console.WriteLine(secondPoint);
            Console.WriteLine(Point3D.center);

            //calculte distance
            double distance = Distance.CalculteDistance(point, secondPoint);
            Console.WriteLine(distance);

            distance = Distance.CalculteDistance(point, Point3D.center);
            Console.WriteLine(distance);

            //Load paths
            List<Path> paths = PathStorage.LoadPaths();

            //print loaded paths
            PrintPaths(paths);

            //Safe path to file
            Point3D firstPathPont = new Point3D(10, 11, 12);
            Point3D secondPathPoint = new Point3D(15, 16, 17);
            Point3D thirdPathPoint = new Point3D(20, 21, 22);

            Path path = new Path(firstPathPont, secondPathPoint, thirdPathPoint);

            PathStorage.SavePath(path);

            List<Path> pathsAfterLoading = PathStorage.LoadPaths();

            //print paths
            PrintPaths(pathsAfterLoading);
        }
Пример #13
0
 static void Main()
 {
     // testing points
     Point3D firstPoint = Point3D.CoordinateSystemCenter;
     Point3D seconPoint = new Point3D(1, 2, 1);
     Console.WriteLine("First point -> " + firstPoint);
     Console.WriteLine("Second point -> " + seconPoint);
     Console.WriteLine("Distance between the two points -> "
         + DistanceBetweenPoints.CaclculateDistance(firstPoint, seconPoint));
     Path myPath = new Path(5);
     myPath.AddPoint(firstPoint);
     myPath.AddPoint(firstPoint);
     myPath.AddPoint(new Point3D(3, 6, 1.5));
     myPath.AddPoint(firstPoint);
     myPath.AddPoint(seconPoint);
     myPath.AddPoint(firstPoint);
     myPath.AddPoint(seconPoint);
     myPath.RemovePoint(seconPoint);
     myPath.RemovePointAt(1);
     PathStorage.SaveToFile(myPath,null);
     Path otherPath = PathStorage.LoadFromFile("../../test.txt");
     otherPath.RemovePoint(firstPoint);
     PathStorage.SaveToFile(otherPath, "text.txt");
 }
Пример #14
0
 public void AddPoint(Point3D p) // add point to path
 {
     this.PointsPath.Add(p);
 }
Пример #15
0
 public static float PointsDistance(Point3D point1, Point3D point2)
 {
     return (float)Math.Sqrt(Math.Pow((point1.X - point2.X), 2) + Math.Pow((point1.Y - point2.Y), 2) + Math.Pow((point1.Z - point2.Z), 2));
 }
Пример #16
0
 public static double CaclculateDistance(Point3D p1, Point3D p2)
 {
     double distance = 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));
     return distance;
 }
Пример #17
0
 public void AddPoint(Point3D point)
 {
     this.points.Add(point);
 }
Пример #18
0
 public static double Calculate(Point3D a,Point3D b)
 {
     double distance = 0;
     distance = Math.Sqrt((a.X - b.X) * (a.Y - b.Y) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z));
     return distance;
 }
Пример #19
0
 public Path(Point3D[] points)
 {
     this.Points = points;
 }
Пример #20
0
 public void TestMethodToString()
 {
     Point3D point = new Point3D(3, 5, 7);
     string result = point.ToString();
     Assert.AreEqual("(3, 5, 7)", result);
 }
Пример #21
0
 public void RemovePoint(Point3D p) // remove point from path
 {
     this.PointsPath.Remove(p);
 }