Example #1
0
 public static void LoadPaths()
 {
     string[] coordinates;
     using (coords)
     {
          coordinates = coords.ReadToEnd().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
     }
     for (int i = 0; i < coordinates.Length; i++)
     {
         string currentPair = coordinates[i];
         string[] currentValuesOfCoordinates = currentPair.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
         for (int j = 0; j < currentValuesOfCoordinates.Length; j++)
         {
             if (j == 0)
             {
                 currentPoint.X = int.Parse(currentValuesOfCoordinates[j]);
             }
             else if (j == 1)
             {
                 currentPoint.Y = int.Parse(currentValuesOfCoordinates[j]);
             }
             else if (j == 2)
             {
                 currentPoint.Z = int.Parse(currentValuesOfCoordinates[j]);
             }
         }
         paths.SequenceOfPoints.Add(currentPoint);
         currentPoint = new Point3D();
     }
     SavePaths(paths);
 }
 public static void SavePath(Point3D point)
 {
     StreamWriter savePath = new StreamWriter(@"..\..\Files\Paths.txt", true);
     using (savePath)
     {
         savePath.WriteLine(point.ToStringForFile());
     }
 }
 public static Path LoadPaths(string filePath)
 {
     Path listOfPaths = new Path();
     StreamReader reader = new StreamReader(filePath);
     using (reader)
     {
         string line = reader.ReadLine();
         while (line != null)
         {
             double[] coordinates = line.Split(' ').Select(double.Parse).ToArray();
             Point3D point = new Point3D(coordinates[0], coordinates[1], coordinates[2]);
             listOfPaths.AddPoint(point);
             line = reader.ReadLine();
         }
     }
     return listOfPaths;
 }
 public void AddPoint(Point3D point)
 {
     this.sequence.Add(point);
 }
Example #5
0
        private static void Main()
        {
            GenericMatrix<int> firstMatrix = new GenericMatrix<int>(3, 2);
            firstMatrix[0, 0] = 1;
            firstMatrix[0, 1] = 2;
            firstMatrix[1, 0] = 3;
            firstMatrix[1, 1] = 4;
            firstMatrix[2, 0] = 5;
            firstMatrix[2, 1] = 6;
            GenericMatrix<int> secondMatrix = new GenericMatrix<int>(3, 2);
            secondMatrix[0, 0] = 1;
            secondMatrix[0, 1] = 2;
            secondMatrix[1, 0] = 0;
            secondMatrix[1, 1] = 4;
            secondMatrix[2, 0] = 5;
            secondMatrix[2, 1] = 6;
                           //Checking the operators for adding, substracting and multiplying
            GenericMatrix<int> resultFromAdding = firstMatrix + secondMatrix;
            GenericMatrix<int> resultFromSubstracting = firstMatrix - secondMatrix;
            GenericMatrix<int> resultFromMultiplication = firstMatrix * secondMatrix;

                               //Showing the attribute at runtime
            Type type = typeof(MainClass);
            object[] attributes = type.GetCustomAttributes(false);

            foreach (object attribute in attributes)
            {
                VersionAttribute version = (VersionAttribute)attribute;
                Console.WriteLine(version.Version);
            }
                
                                  //Checking the true operator
            if (secondMatrix)
            {
                Console.WriteLine("SecondMatrix Contains Zero");
            }
            else
            {
                Console.WriteLine("SecondMatrix Not Contains Zero");
            }


            //Console.WriteLine(matrix[2,1]);
            //matrix[1, 1] = 5;
            //matrix[0, 1] = 3;
            //matrix[1, 1] = 4;


            Point3D newpoint = new Point3D();
            newpoint.X = 5;
            newpoint.Y = 8;
            newpoint.Z = 1;
            //The overrided ToString() prints us the points on the console

            //newpoint.ToString();

            //This is the static point with coordinates 5,5,5 to test it because 0,0,0 is by default and it will
            //aways work

            //Point3D.ZeroPoint.ToString();

            Point3D ad = new Point3D(4, 5, 6);

            //This Class creates List of paths
            Path newPath = new Path();
            newPath.SequenceOfPoints.Add(newpoint);
            newPath.SequenceOfPoints.Add(Point3D.ZeroPoint);
            newPath.SequenceOfPoints.Add(ad);

                //This class Saves the currentPath in text file, you can type the name and it will appear in the
                    //Files folder "../../Files" in the project

            // PathStorage.SavePaths(newPath, "mitko.doc");

                    // This will load a coordinate file from the same directory - Files and will split and initialize
                  // them and will save them in SavedPaths.txt automaticly

            //PathStorage.LoadPaths();

                         //This is Class that calculate the difference between two points

            //DistanceBetweenPoints.DistanceBetweenPoint(newpoint, Point3D.ZeroPoint);


            GenericList<int> test = new GenericList<int>(5);
            test.Add(5);
            test.Add(34);
            test.Remove(0);
            test.Insert(2, 1);
            test.Add(4);
            test.Insert(3, 1);

            test.Insert(4, 1);

            test.Add(8);
            //Auto grow functionality is turned on from now on
            test.Add(9);
            test.Add(10);
            //Gets the minValue in the GenericList
            test.Min();
            test.Max();
            //this is for testing the object states
            //Console.WriteLine(test[0] + " " + test[1] + " " + test[2] + " " + test[3]);
            //testing the ToString()
            //Console.WriteLine(test[0].ToString());
            test.Contains(2);
            test.Contains(100);
        }
 //TODO:
 //http://www.calculatorsoup.com/calculators/geometry-solids/distance-two-points.php
 public static double CalculateDistanceBetweenPoints(Point3D firstPoint, Point3D secondPoint)
 {
     double distance = Math.Sqrt(Math.Pow((secondPoint.X - firstPoint.X), 2) + Math.Pow((secondPoint.Y - firstPoint.Y), 2) + Math.Pow((secondPoint.Z - firstPoint.Z), 2));
     return distance;
 }