Exemplo n.º 1
1
 public static void SavePointsInFile(string fileName, Path3D path)
 {
     using (StreamWriter file = new StreamWriter(fileName))
     {
         file.Write(path);
     }
 }
Exemplo n.º 2
0
        public static string Save3dPoints(Path3D path)
        {
            try
            {
                FileStream stream = new FileStream("3DPaths.txt", FileMode.Create);

                StreamWriter sw = new StreamWriter(stream);

                foreach (Point3D currentPoint in path.SequenceOfPoints)
                {
                    sw.Write(currentPoint.X);
                    sw.Write(" ");
                    sw.Write(currentPoint.Y);
                    sw.Write(" ");
                    sw.Write(currentPoint.Z);
                    sw.WriteLine();
                }

                sw.Close();
                stream.Close();
            }
            catch (Exception)
            {
                string message = "There are some problems. Sequence wasnt saved.";

                return(message);
            }

            string confirmation = "Sequence saved.";

            return(confirmation);
        }
Exemplo n.º 3
0
        public static Path3D Load3dPoints()
        {
            FileStream stream = new FileStream("3DPaths.txt", FileMode.Open, FileAccess.Read);

            StreamReader sr = new StreamReader(stream);

            List <Point3D> loadedPoints = new List <Point3D>();

            while (!sr.EndOfStream)
            {
                string[] currentCoordinatesString = sr.ReadLine().Split(' ');

                double[] currentCoordinatesDouble = new double[3];

                for (int i = 0; i < currentCoordinatesDouble.Length; i++)
                {
                    currentCoordinatesDouble[i] = Convert.ToDouble(currentCoordinatesString[i]);
                }

                Point3D currentPoint = new Point3D(currentCoordinatesDouble[0], currentCoordinatesDouble[1], currentCoordinatesDouble[2]);

                loadedPoints.Add(currentPoint);
            }

            Path3D path = new Path3D(loadedPoints);

            return(path);
        }
Exemplo n.º 4
0
        public static bool WritePath(Path3D pathInSpace, string pathName, string pathDescription = null, string outputFolderName = null, string ouputFolderPath = null)
        {
            outputFolderName = outputFolderName ?? DefaultFolderName;
            ouputFolderPath = ouputFolderPath ?? DefaultFolderPath;

            var directory = Directory.CreateDirectory(Path.Combine(ouputFolderPath, outputFolderName)); //if it doesn't exist create directory
            string filePath = Path.Combine(ouputFolderPath, outputFolderName, pathName + "." + FileExtension);

            if (string.IsNullOrWhiteSpace(pathName) || File.Exists(filePath))
                return false;

            var pathInfo = new PathInfo()
            {
                PathName = pathName,
                PathDescription = pathDescription ?? DefaultPathDetails,
                Path = pathInSpace.Points
            };

            string obj = JsonConvert.SerializeObject(pathInfo, Formatting.Indented);

            using (StreamWriter writer = new StreamWriter(filePath))
                writer.Write(obj);

            return true;
        }
Exemplo n.º 5
0
	static void Main()
	{
		Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
		// first test point
		Point3D firstPoint3D = new Point3D(1.2, 2.4, 3.7);
		Console.WriteLine("Point({0})", firstPoint3D);

		// second test point
		Point3D secondPoint3D = Point3D.ZeroPoint3D;
		Console.WriteLine("Point({0})", secondPoint3D);

		// calculate the points distance
		Console.WriteLine("Distance between test points: {0:F2}", Point3D.Distance.CalcDistance(firstPoint3D, secondPoint3D));

		// sequence of points => path
		var path = new Path3D(new Point3D(1, 1, 1), new Point3D(2, 2, 2));
		path.Add(new Point3D(3, 3, 3));
		path.Remove(new Point3D(1, 1, 1));
		Console.WriteLine(Environment.NewLine + "Points in path (total: {0})"+ Environment.NewLine + "{1}", path.Count, path);
		path.Clear();

		// load new points from input.txt
		path = Path3D.PathStorage.LoadPaths("../../input.txt");
		Console.WriteLine(Environment.NewLine + "Points in path (total: {0})" + Environment.NewLine + "{1}", path.Count, path);

		// save points in output.txt
		// path.Clear();
		Path3D.PathStorage.SavePaths(path, "../../output.txt");
	}
Exemplo n.º 6
0
 public static void SavePath(Path3D path, string fileName)
 {
     using (var writer = new StreamWriter(fileName))
     {
         writer.WriteLine(path);
     }
 }
Exemplo n.º 7
0
        public static Path3D LoadPath(string fileName)
        {
            var path = new Path3D(new List<Point3D>());

            using (var reader = new StreamReader(fileName))
            {
                var line = reader.ReadLine();

                const string pattern = "Point #[0-9]+, Coordinates:{ (-?[0-9]+\\.?[0-9]*), (-?[0-9]+\\.?[0-9]*), (-?[0-9]+\\.?[0-9]*) }";

                while (line != null)
                {
                    if (line != "")
                    {
                        var matches = Regex.Matches(line, pattern);

                        if (matches[0].Groups.Count == 4)
                        {
                            var x = double.Parse(matches[0].Groups[1].Value);
                            var y = double.Parse(matches[0].Groups[2].Value);
                            var z = double.Parse(matches[0].Groups[3].Value);
                            var point = new Point3D(x, y, z);
                            path.PointsSequence.Add(point);
                        }
                    }

                    line = reader.ReadLine();
                }
            }
            return path;
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
 public void Update(Path3D path)
 {
     if (DrawBezierDebugLines)
     {
         PathUtility.DebugDrawSpline(path, 32);
     }
 }
Exemplo n.º 10
0
    public static Path3D LoadPaths(string fileName)
    {
        try
        {
            string input = File.ReadAllText(fileName);

            string pattern = @"X=(.+?), Y=(.+?), Z=(.+?)";
            var    reg     = new Regex(pattern);
            var    matchs  = reg.Matches(input);

            Path3D path = new Path3D();
            foreach (Match match in matchs)
            {
                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 point = new Point3D(x, y, z);
                path.AddPoint(point);
            }
            return(path);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            throw ex.InnerException;
        }
    }
Exemplo n.º 11
0
    static void Main()
    {
        Console.WriteLine("Point3D Test:");
        Point3D[] points = new Point3D[3];
        points[0] = new Point3D(1, -19, 17);
        points[1] = new Point3D(2, 0, -7);
        points[2] = Point3D.StartingPoint;

        foreach (var point in points)
        {
            Console.WriteLine(point.ToString());
        }

        Console.WriteLine("---------------------------------------\nDistance Calculator Test:");

        Console.WriteLine("Distance between A{0} and B{1}: {2}",
            points[0].ToString(),
            points[1].ToString(),
            DistanceCalculator.Calculate3DDistance(points[0], points[1]));

        Console.WriteLine("---------------------------------------\nPaths Test:");

        Path3D path3D = new Path3D();
        path3D.AddMultiple3DPoints(points);

        Storage.Save(path3D, "../../points.txt");

        Path3D sndPath3D = Storage.Load("../../points.txt");

        for (int i = 0; i < sndPath3D.NumberOfPoints(); i++)
        {
            Console.WriteLine(sndPath3D.Get3DPoint(i).ToString());
        }
    }
Exemplo n.º 12
0
    private static void Main()
    {
        Console.WriteLine("Problem 1. Point3D");
        Point3D p1 = new Point3D(1, 2, 3);
        Point3D p2 = new Point3D(3.4, 4.66, 5.55);

        Console.WriteLine(p1);
        Console.WriteLine(p2);
        Console.WriteLine(Point3D.StartPoint);
        Console.WriteLine();

        Console.WriteLine("Problem 2. Distance Calculator");
        double distance = DistanceCalculator.CalculateDistance(p1, p2);

        Console.WriteLine(distance);
        Console.WriteLine();

        Console.WriteLine("Problem 3. Paths3D");
        Path3D path = new Path3D(p1, p2, Point3D.StartPoint);

        Console.WriteLine("Save path: {0}", path);
        Storage.SavePathInFile("path.txt", path);
        Path3D loadPath = Storage.LoadPathOfFile("path.txt");

        Console.WriteLine("Load path: {0}", loadPath);
    }
Exemplo n.º 13
0
        public static Path3D LoadPath(string fileName)
        {
            List<Point3D> points = new List<Point3D>();
            Path3D path;

            try
            {
                StreamReader sr = new StreamReader(fileName);
                using (sr)
                {
                    String line = sr.ReadLine();
                    while (line != null)
                    {
                        double[] coordinates = PointExtractor(line);
                        Point3D p = new Point3D(coordinates[0], coordinates[1], coordinates[2]);
                        points.Add(p);
                        line = sr.ReadLine();
                    }
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            path = new Path3D(points);
            return path;
        }
Exemplo n.º 14
0
    static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        // first test point
        Point3D firstPoint3D = new Point3D(1.2, 2.4, 3.7);

        Console.WriteLine("Point({0})", firstPoint3D);

        // second test point
        Point3D secondPoint3D = Point3D.ZeroPoint3D;

        Console.WriteLine("Point({0})", secondPoint3D);

        // calculate the points distance
        Console.WriteLine("Distance between test points: {0:F2}", Point3D.Distance.CalcDistance(firstPoint3D, secondPoint3D));

        // sequence of points => path
        var path = new Path3D(new Point3D(1, 1, 1), new Point3D(2, 2, 2));

        path.Add(new Point3D(3, 3, 3));
        path.Remove(new Point3D(1, 1, 1));
        Console.WriteLine(Environment.NewLine + "Points in path (total: {0})" + Environment.NewLine + "{1}", path.Count, path);
        path.Clear();

        // load new points from input.txt
        path = Path3D.PathStorage.LoadPaths("../../input.txt");
        Console.WriteLine(Environment.NewLine + "Points in path (total: {0})" + Environment.NewLine + "{1}", path.Count, path);

        // save points in output.txt
        // path.Clear();
        Path3D.PathStorage.SavePaths(path, "../../output.txt");
    }
Exemplo n.º 15
0
    static void Main(string[] args)
    {
        // Create instances from namespace Geometry2D
        Point2D point2D = new Point2D();
        Circle  circle  = new Circle();
        DistanceCalculator2D distance2D = new DistanceCalculator2D();
        Ellipse   ellipse   = new Ellipse();
        Figure2D  figure2D  = new Figure2D();
        Polygon   polygon   = new Polygon();
        Rectangle rectangle = new Rectangle();
        Square    square    = new Square();

        // Create instances from namespace Geometry3D
        DistanceCalculator3D distance3D = new DistanceCalculator3D();
        Path3D  path3D  = new Path3D();
        Point3D point3D = new Point3D();

        // Create instances from namespace Storage
        GeometryBinaryStorage binaryStorage = new GeometryBinaryStorage();
        GeometrySVGStorage    svgStorage    = new GeometrySVGStorage();
        GeometryXMLStorage    xmlStorage    = new GeometryXMLStorage();

        // Create instances from namespace UI
        Screen2D screen2D = new Screen2D();
        Screen3D screen3D = new Screen3D();
    }
Exemplo n.º 16
0
    public static Path3D GetPathFromFile(string fileName)
    {
        string folderPath = string.Format(@"..\..\StorageFolder\{0}.txt",
                                          fileName);
        Path3D         extractedPath = null;
        Point3D        bufferPoint;
        List <Point3D> extractedList = new List <Point3D>();
        StreamReader   readFile      = new StreamReader(folderPath);

        using (readFile)
        {
            while (true)
            {
                string line = readFile.ReadLine();
                if (line == null)
                {
                    break;
                }
                MatchCollection values = Regex.Matches(line, @"(\-{0,1}[0-9]+(\.{0,1}[0-9]+)*)");
                if (values.Count == 3)
                {
                    double x = Double.Parse(values[0].ToString());
                    double y = Double.Parse(values[1].ToString());
                    double z = Double.Parse(values[2].ToString());
                    bufferPoint = new Point3D(x, y, z);
                    extractedList.Add(bufferPoint);
                }
            }
        }
        if (extractedList.Count > 0)
        {
            extractedPath = new Path3D(extractedList);
        }
        return(extractedPath);
    }
Exemplo n.º 17
0
        public static bool WritePath(Path3D pathInSpace, string pathName, string pathDescription = null, string outputFolderName = null, string ouputFolderPath = null)
        {
            outputFolderName = outputFolderName ?? DefaultFolderName;
            ouputFolderPath  = ouputFolderPath ?? DefaultFolderPath;

            var    directory = Directory.CreateDirectory(Path.Combine(ouputFolderPath, outputFolderName)); //if it doesn't exist create directory
            string filePath  = Path.Combine(ouputFolderPath, outputFolderName, pathName + "." + FileExtension);

            if (string.IsNullOrWhiteSpace(pathName) || File.Exists(filePath))
            {
                return(false);
            }

            var pathInfo = new PathInfo()
            {
                PathName        = pathName,
                PathDescription = pathDescription ?? DefaultPathDetails,
                Path            = pathInSpace.Points
            };

            string obj = JsonConvert.SerializeObject(pathInfo, Formatting.Indented);

            using (StreamWriter writer = new StreamWriter(filePath))
                writer.Write(obj);

            return(true);
        }
Exemplo n.º 18
0
    public static Path3D LoadPaths(string fileName)
    {
        try
        {
            string input = File.ReadAllText(fileName);

            string pattern = @"X=(.+?), Y=(.+?), Z=(.+?)";
            var reg = new Regex(pattern);
            var matchs = reg.Matches(input);

            Path3D path = new Path3D();
            foreach (Match match in matchs)
            {
                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 point = new Point3D(x, y, z);
                path.AddPoint(point);
            }
            return path;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            throw ex.InnerException;
        }
    }
Exemplo n.º 19
0
 public static void SavePathInFile(string fileName, Path3D path)
 {
     using (StreamWriter writer = new StreamWriter(fileName))
     {
         writer.Write(path);
     }
 }
        public static void Main()
        {
            // The first three problems are in this project

            Point3D point = new Point3D(5.4m, 6.6m, 3.1m);

            Console.WriteLine(point);

            Point3D anotherPoint = new Point3D(1m, 5.78m, -2.75m);

            Console.WriteLine(anotherPoint);

            Console.WriteLine("{0:F3}", DistanceCalculation.CalculateDistance(point, anotherPoint));

            Point3D basePoint = Point3D.StartingPoint;

            Console.WriteLine(basePoint);

            Path3D listOfPoints = new Path3D();

            listOfPoints.AddPoint(point);
            listOfPoints.AddPoint(basePoint);
            listOfPoints.AddPoint(anotherPoint);

            Storage.SavePath(listOfPoints);
        }
Exemplo n.º 21
0
 public static void SavePathInFile(string fileName, Path3D path)
 {
     using (StreamWriter writer = new StreamWriter(fileName))
     {
         writer.Write(path);
     }
 }
Exemplo n.º 22
0
    public static Path3D LoadPathOfFile(string fileName)
    {
        Path3D path = new Path3D();

        using (StreamReader sr = new StreamReader(fileName))
        {
            string input = sr.ReadToEnd();

            string pattern = "{([\\d,.]+), ([\\d,.]+), ([\\d,.]+)}";

            var reg = new Regex(pattern);
            var matches = reg.Matches(input);

            if (matches.Count <= 0)
            {
                throw new ApplicationException("Invalid data in file " + fileName);
            }

            foreach (Match match in matches)
            {
                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 p = new Point3D(x, y, z);
                path.AddPoint(p);
            }
        }

        return path;
    }
Exemplo n.º 23
0
    public static Path3D LoadPathOfFile(string fileName)
    {
        Path3D path = new Path3D();

        using (StreamReader reader = new StreamReader(fileName))
        {
            string input = reader.ReadToEnd();

            string pattern = "{([\\d,.]+), ([\\d,.]+), ([\\d,.]+)}";

            var reg     = new Regex(pattern);
            var matches = reg.Matches(input);

            if (matches.Count <= 0)
            {
                throw new ApplicationException("Invalid data in file " + fileName);
            }

            foreach (Match match in matches)
            {
                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 p = new Point3D(x, y, z);
                path.AddPoint(p);
            }
        }

        return(path);
    }
Exemplo n.º 24
0
    static void Main()
    {
        Console.WriteLine(Storage.ReadPath());

        List <Point3D> points = new List <Point3D>();

        while (true)
        {
            Console.WriteLine("Please enter three points separated by a space or type \"Exit\" to exit");
            string line = Console.ReadLine();
            if (line == "Exit" || line == "exit")
            {
                break;
            }
            string[] numbers = line.Split(' ');
            float    x       = float.Parse(numbers[0]);
            float    y       = float.Parse(numbers[1]);
            float    z       = float.Parse(numbers[2]);
            Point3D  point   = new Point3D(x, y, z);
            points.Add(point);
        }
        Path3D path = new Path3D(points);

        Storage.WritePath(path);
    }
Exemplo n.º 25
0
    public static Path3D LoadPath()
    {
        Path3D result = new Path3D();

        //TODO;

        return result;
    }
Exemplo n.º 26
0
    private void Start()
    {
        if (PathObject == null)
            PathObject = this.gameObject;
        path = PathUtility.GetPath3D(PathObject);

        lineRenderer = GetComponent<LineRenderer>();
        UpdateLineRendererVertices();
    }
Exemplo n.º 27
0
 public static void WritePath(Path3D path)
 {
     using (StreamWriter writer = new StreamWriter(@"../../paths/pathsoutput.txt"))
     {
         string pathString = path.ToString();
         pathString = pathString.Replace("\n", Environment.NewLine);
         writer.WriteLine(pathString);
     }
 }
Exemplo n.º 28
0
 public static void Save(Path3D path3D, string path)
 {
     using (StreamWriter writer = new StreamWriter(path))
     {
         for (int i = 0; i < path3D.NumberOfPoints(); i++)
         {
             writer.WriteLine(path3D.Get3DPoint(i).ToString());
         }
     }
 }
    static void Main(string[] args)
    {
        Path3D path = new Path3D("../../Path.txt");
        Console.WriteLine(path.ToString());
        path.addPoint(new Point3D(50, 10, 12));
        path.addPoint(new Point3D(7, 9, 12.5));
        Console.WriteLine(path.ToString());

        path.saveChanges("../../Path.txt");
    }
Exemplo n.º 30
0
 public static void SavePath(string destination, Path3D path)
 {
     using (StreamWriter writer = new StreamWriter(destination))
     {
         foreach (Point3D point in path.PointInPath)
         {
             writer.WriteLine("{0} {1} {2}", point.Xaxis, point.Yaxis, point.Zaxis);
         }
     }
 }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            Circle circle = new Circle();

            Path3D path = new Path3D();

            GeometryBinaryStorage gbs = new GeometryBinaryStorage();

            Screen2D screen  = new Screen2D();
            Screen3D screen1 = new Screen3D();
        }
Exemplo n.º 32
0
    public static void SavePaths(Path3D Points)
    {
        string line = "";

        foreach (Point3D Point in Points.PointStorage)
        {
            line += Point.X.ToString() + ',' + Point.Y.ToString() + ',' + Point.Z.ToString() + ';';
        }

        System.IO.File.WriteAllText(@"E:\Programming\OOP\text.txt", line);
    }
Exemplo n.º 33
0
    private void Start()
    {
        if (PathObject == null)
        {
            PathObject = this.gameObject;
        }
        path = PathUtility.GetPath3D(PathObject);

        lineRenderer = GetComponent <LineRenderer>();
        UpdateLineRendererVertices();
    }
Exemplo n.º 34
0
        public static void SavePathToFile(Path3D path, string filePath)
        {
            var sb = new StringBuilder();

            foreach (var point in path)
            {
                sb.AppendLine($"{point.X}, {point.Y}, {point.Z}");
            }

            File.WriteAllText(filePath, sb.ToString().TrimEnd());
            Console.WriteLine($"Path saved to {filePath}");
        }
Exemplo n.º 35
0
        private static void Main(string[] args)
        {
            Point3D firstPoint  = new Point3D(0, 0, 2);
            Point3D secondPoint = new Point3D(7, 1, -3);
            Point3D thirdPoint  = new Point3D(4, 2, 3);

            Path3D sequence = new Path3D(firstPoint, secondPoint);

            sequence.AddToPath(thirdPoint);
            Storage.SavePath(sequence);
            Storage.ReadPath();
        }
Exemplo n.º 36
0
    public static void Write(Path3D path)
    {
        StreamWriter writer = new StreamWriter("../../text.txt");

        using (writer)
        {
            int lineNumber = 0;
            foreach (var item in path.Path)
            {
                lineNumber++;
                writer.WriteLine("Point #{0}: [{1}];", lineNumber, item);
            }
        }
    }
Exemplo n.º 37
0
        static void Main(string[] args)
        {
            var path = new Path3D(
                new Point3D(11, 2.2, 6),
                new Point3D(4, 5, 83.2),
                new Point3D(0, 0, 0),
                new Point3D(3, 12, 13));

            Storage.SavePath(File, path);

            Path3D path1 = Storage.LoadPath(File);

            Console.WriteLine(string.Join(Environment.NewLine, path1.Path));
        }
Exemplo n.º 38
0
    static void Main()
    {
        Point3D pointA = new Point3D(3.5, 2, 4.86);
        Point3D pointB = new Point3D(10, 5.2, 15);

        Console.WriteLine(pointA.ToString());
        Console.WriteLine(pointB.ToString());
        Console.WriteLine(Point3D.StartingPoint);

        Console.WriteLine(String.Format("{0:0.##}", DistanceCalculator.distCalculator(pointA, pointB)));

        Path3D path = new Path3D(pointA, pointB, Point3D.StartingPoint);
        Console.WriteLine("{0}", path);
    }
Exemplo n.º 39
0
    public static void Write(Path3D path)
    {
        StreamWriter writer = new StreamWriter("../../text.txt");

        using (writer)
        {
            int lineNumber = 0;
            foreach (var item in path.Path)
            {
                lineNumber++;
                writer.WriteLine("Point #{0}: [{1}];", lineNumber, item);
            }
        }
    }
Exemplo n.º 40
0
        /// <summary>
        /// Calculates path in current thread and returns the result
        /// </summary>
        /// <param name="start"></param>
        /// <param name="isGoal">allows to stop search at the alternative goal point</param>
        /// <param name="getSuccessors"></param>
        /// <param name="estimate"></param>
        public Path3D CalculateCustomPath(Vector3I start, Predicate <AStarNodeFunc3D> isGoal, Action <AStarNodeFunc3D, List <AStarNodeFunc3D> > getSuccessors, Func <AStarNodeFunc3D, double> estimate)
        {
            AStarFunc <AStarNodeFunc3D> calculator = null;

            lock (_pathPool)
            {
                if (_pathPool.Count > 0)
                {
                    calculator = _pathPool.Dequeue();
                }
            }

            if (calculator == null)
            {
                calculator = new AStarFunc <AStarNodeFunc3D>();
            }

            var startNode = new AStarNodeFunc3D(GetCursor(start), null, 1);

#if DEBUG
            var sw = Stopwatch.StartNew();
#endif
            calculator.FindPath(startNode, isGoal, getSuccessors, estimate);
#if DEBUG
            sw.Stop();
#endif
            var path = new Path3D {
                Start = start
            };
#if DEBUG
            path.PathFindTime        = sw.Elapsed.TotalMilliseconds;
            path.IterationsPerformed = calculator.Iterations;
#endif

            if (calculator.Solution != null)
            {
                var list = calculator.Solution.Select(node3D => node3D.Cursor.GlobalPosition).ToList();

                path.Points = list;
                path.Goal   = list.LastOrDefault();
            }

            lock (_pathPool)
            {
                _pathPool.Enqueue(calculator);
            }

            return(path);
        }
Exemplo n.º 41
0
    public void OnPathFound(Vector3[] waypoints, bool pathSuccessful)
    {
        if (pathSuccessful)
        {
            path = new Path3D(waypoints, transform.position, turnDst, stoppingDst);

            StopCoroutine("FollowPath");
            StartCoroutine("FollowPath");
        }
        else
        {
            //Cannot reach the player!
            //Stop the coroutines and set canTeleport to true.
        }
    }
Exemplo n.º 42
0
 public static void SavePath(string fileName, Path3D path)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(fileName, true, Encoding.GetEncoding("UTF-8")))
         {
             sw.WriteLine(path.ToString());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex.InnerException;
     }
 }
Exemplo n.º 43
0
    static void Main()
    {
        Point3D pointA = new Point3D(3.5, 2, 4.86);
        Point3D pointB = new Point3D(10, 5.2, 15);

        Console.WriteLine(pointA.ToString());
        Console.WriteLine(pointB.ToString());
        Console.WriteLine(Point3D.StartingPoint);

        Console.WriteLine(String.Format("{0:0.##}", DistanceCalculator.distCalculator(pointA, pointB)));

        Path3D path = new Path3D(pointA, pointB, Point3D.StartingPoint);

        Console.WriteLine("{0}", path);
    }
Exemplo n.º 44
0
 public static void SavePathToTxt(string file, Path3D inPath)
 {
     string path = file;
     if (!File.Exists(path))
     {
         // Create a file to write to.
         using (StreamWriter sw = File.CreateText(path))
         {
             foreach (var item in inPath.PointsList3D)
             {
                 sw.WriteLine(item);
             }
         }
     }
 }
Exemplo n.º 45
0
        public static void Main(string[] args)
        {
            var path = new Path3D(
                new Point3D(5, 9, 4),
                new Point3D(15, 16, 8.2),
                new Point3D(0, 0, 0),
                new Point3D(51, 122, 133));


            Storage.SavePath(File, path);


            Path3D path2 = Storage.LoadPath(File);

            Console.WriteLine(string.Join(Environment.NewLine, path2.Path));
        }
Exemplo n.º 46
0
    public static void SavePath(string fileName, Path3D path)
    {
        try
        {
            using (StreamWriter sw = new StreamWriter(fileName, true, Encoding.GetEncoding("UTF-8")))
            {
                sw.WriteLine(path.ToString());
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            throw ex.InnerException;
        }

    }
Exemplo n.º 47
0
    private void Start()
    {
        for (float i = 0; i <= 1.0f; i += Divisor)
        {
            for (float j = 0; j <= 1.0f; j += Divisor)
            {
                for (float k = 0; k <= 1.0f; k += Divisor)
                {
                    // Create sphere
                    GameObject g = GameObject.CreatePrimitive(PrimitiveType.Sphere);

                    // Scale sphere to quarter size of incrementation (quarter for decent margins)
                    g.transform.localScale = Vector3.one * Divisor * RelativeScale;

                    // Set up space distortion component and appropriate value
                    PathsDemo_SpaceDistortion gSpaceDistortion = g.AddComponent <PathsDemo_SpaceDistortion>();
                    gSpaceDistortion.XPath = this.XPath;
                    gSpaceDistortion.YPath = this.YPath;
                    gSpaceDistortion.ZPath = this.ZPath;
                    gSpaceDistortion.t     = i;
                    gSpaceDistortion.u     = j;
                    gSpaceDistortion.v     = k;

                    // Attach material
                    g.GetComponent <Renderer>().material = LatticeMat;

                    // Keep track of number of objects
                    count++;

                    // don't generate along Z axis
                    if (twoDimensional)
                    {
                        break;
                    }
                }
            }
        }

        Debug.Log("Number of spheres: " + count);
        //Destroy(this.gameObject);

        x = PathUtility.GetPath3D(XPath);
        z = PathUtility.GetPath3D(ZPath);

        GameObject.Find("Title").GetComponent <GUIText>().text += " " + count + " Objects";
        GameObject.Find("PathsDemo_Screen").GetComponent <PathsDemo_DemoScreen>().EVALCOUNT = count * 3;
    }
Exemplo n.º 48
0
        public static Path3D LoadPathFromFile(string filePath)
        {
            Path3D path = new Path3D();

            foreach (var line in File.ReadLines(filePath))
            {
                var tokens = line.Split(new[] {", "}, StringSplitOptions.None);

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

                path.Add(new Point3D(x, y, z));
            }

            return path;
        }
Exemplo n.º 49
0
    public static void StorePath(Path3D path, string fileName)
    {
        string     filePath    = string.Format(@"..\..\StorageFolder\{0}.txt", fileName);
        FileStream writeStream = new FileStream(filePath, FileMode.Create);
        string     lineHolder  = "";

        using (writeStream)
        {
            for (int x = 0; x < path.GetLength(); x++)
            {
                lineHolder = string.Format("{0} {1} {2}{3}",
                                           path[x].XAxis, path[x].YAxis, path[x].ZAxis,
                                           Environment.NewLine);
                byte[] buffer = new UTF8Encoding(true).GetBytes(lineHolder);
                writeStream.Write(buffer, 0, buffer.Length);
            }
        }
    }
Exemplo n.º 50
0
    static void Main()
    {
        List<Point3D> listOfPoints = new List<Point3D>();
        listOfPoints.Add(Point3D.StartingPoint);
        listOfPoints.Add(new Point3D(0, 1, 2));
        listOfPoints.Add(new Point3D(1.5, -3.4));
        listOfPoints.Add(new Point3D(-3.1, 0, 4));

        Path3D path = new Path3D(listOfPoints);
        path.AddPointToPath(new Point3D(0, -1, 1.1111111));
        Console.WriteLine(path);

        string fileLocation = "Path3D.txt";
        Storage.SavePathToFile(fileLocation, path);

        Path3D pathFromFile = Storage.LoadPathFromFile(fileLocation);
        Console.WriteLine(pathFromFile);
    }
Exemplo n.º 51
0
        public static void Main()
        {
            var points = new Path3D()
            {
                new Point3D(1.3, 2, 5.8),
                new Point3D(4, 2, 8),
                new Point3D(34, 2, 43),
                new Point3D(-5, 2, -8),
                new Point3D(0, 10, 8),
                new Point3D(0, 0, -8),
                new Point3D(1, 6, 88),
                new Point3D(4, 22, -13),
            };

            Storage.Save(points);
            var a = Storage.Load();
            Console.WriteLine(a);
        }
Exemplo n.º 52
0
        public static void WritePath(Path3D path)
        {
            StreamWriter streamWriter = new StreamWriter(fileName);

            using (streamWriter)
            {
                int pathCountPoints = path.CountPoints;

                for (int i = 0; i < pathCountPoints; i++)
                {
                    Point3D p     = path.Points3D[i];
                    string  fLine = p.X + " " + p.Y + " " + p.Z;
                    streamWriter.WriteLine(fLine);
                }

                streamWriter.Close();
            }
        }
Exemplo n.º 53
0
        /// <summary>
        /// Loads the 3D-points located in the text file to a list of points in 3Dspace. 
        /// </summary>
        /// <returns>Returns an <param name="Path"/> list of Point3D objects, representing points in space.</returns>
        public static Path3D Load(string file = null)
        {
            string currentPath = path;
            if (!string.IsNullOrWhiteSpace(file))
            {
                currentPath = file;
            }

            // instantiates the List to be returned
            var listCoordinates = new Path3D();
            using (var reader = new StreamReader(currentPath, Encoding.UTF8))
            {
                while (reader.Peek() > -1)
                {
                    // declate object to hold coordinates {x,y,z}
                    var point = new Point3D();
                    try
                    {
                        var line = reader.ReadLine();
                        if (line == null)
                        {
                            continue;
                        }

                        string[] lineWithCoordinates = line.Trim().Split((char)9);

                        // convert each component of 3D-coordinate to daouble and add it to the List of 3-D coordinates
                        point.X = double.Parse(lineWithCoordinates[0]);
                        point.Y = double.Parse(lineWithCoordinates[1]);
                        point.Z = double.Parse(lineWithCoordinates[2]);
                        listCoordinates.Add(point);
                    }
                    catch
                    {
                        // handling exception if some of the coordinates are not numbers
                        throw new ArgumentOutOfRangeException("Coordinates", "There are values which are not valid coordinates in the text file!.");
                    }
                }
            }

            return listCoordinates;
        }
Exemplo n.º 54
0
    static void Main(string[] args)
    {
        Point3D testPoint = new Point3D(1.1, 2.4, 3.0);
        //Console.WriteLine(testPoint);
        //Console.WriteLine(Point3D.StartPointToString());
        Point3D sPoint = Point3D.GetStartPoint();

        //Console.WriteLine(sPoint);

        //Console.WriteLine(DistanceCalculator.GetTheDistance(sPoint, testPoint));
        Console.WriteLine(DistanceCalculator.DistanceCalcDetails(sPoint, testPoint));

        try
        {
            List <Point3D> pointsList = new List <Point3D>();
            pointsList.Add(sPoint);
            pointsList.Add(testPoint);
            pointsList.Add(sPoint);
            pointsList.Add(testPoint);
            pointsList.Add(sPoint);
            pointsList.Add(testPoint);
            pointsList.Add(sPoint);
            pointsList.Add(testPoint);
            pointsList.Add(sPoint);
            pointsList.Add(testPoint);
            Path3D testPath = new Path3D(pointsList);
            Storage.StorePath(testPath, "testFile");
            Console.WriteLine("Path Success!");
            Path3D extractedPath = Storage.GetPathFromFile("testFile");
            Console.WriteLine(extractedPath);
        }
        catch (ArgumentNullException arEx)
        {
            Console.WriteLine("Unset List!\n"
                              + arEx.Message);
        }
        catch (ArgumentException arEx)
        {
            Console.WriteLine("Zero List Count!\n"
                              + arEx.Message);
        }
    }
Exemplo n.º 55
0
        static void Main(string[] args)
        {
            Storage.Save("7 0 13|2 17 88", "text");
            var points = new List<Point>
            {
                new Point(1 , 3, 5),
                new Point(2 , 3, 5),
                new Point(5 , 13, 51),
                new Point(1 , 3, 25),
                new Point(1 , 3, 5),
                new Point(4 , 3, 6),
            };

            Storage.Save(points, "text2");

            var loadedPoints = Storage.Load("text2");
            var path = new Path3D(loadedPoints);

            Console.WriteLine(path);
        }
Exemplo n.º 56
0
        static void Main(string[] args)
        {
            Storage.Save("1 2 3|12 34 4", "saved");
            var points = new List<Point>
            {
                new Point(1 , 3, 5),
                new Point(2 , 3, 5),
                new Point(5 , 13, 51),
                new Point(1 , 3, 25),
                new Point(1 , 3, 5),
                new Point(4 , 3, 6),
            };

            Storage.Save(points, "saved1");

            var loadedPoints = Storage.Load("saved1");
            var path = new Path3D(loadedPoints);

            Console.WriteLine(path);
        }
    private void Start()
    {
        for (float i = 0; i <= 1.0f; i += Divisor)
            for (float j = 0; j <= 1.0f; j += Divisor)
                for (float k = 0; k <= 1.0f; k += Divisor)
                {
                    // Create sphere
                    GameObject g = GameObject.CreatePrimitive(PrimitiveType.Sphere);

                    // Scale sphere to quarter size of incrementation (quarter for decent margins)
                    g.transform.localScale = Vector3.one * Divisor * RelativeScale;

                    // Set up space distortion component and appropriate value
                    PathsDemo_SpaceDistortion gSpaceDistortion = g.AddComponent<PathsDemo_SpaceDistortion>();
                    gSpaceDistortion.XPath = this.XPath;
                    gSpaceDistortion.YPath = this.YPath;
                    gSpaceDistortion.ZPath = this.ZPath;
                    gSpaceDistortion.t = i;
                    gSpaceDistortion.u = j;
                    gSpaceDistortion.v = k;

                    // Attach material
                    g.GetComponent<Renderer>().material = LatticeMat;

                    // Keep track of number of objects
                    count++;

                    // don't generate along Z axis
                    if (twoDimensional)
                        break;
                }

        Debug.Log("Number of spheres: " + count);
        //Destroy(this.gameObject);

        x = PathUtility.GetPath3D(XPath);
        z = PathUtility.GetPath3D(ZPath);

        GameObject.Find("Title").GetComponent<GUIText>().text += " " + count + " Objects";
        GameObject.Find("PathsDemo_Screen").GetComponent<PathsDemo_DemoScreen>().EVALCOUNT = count * 3;
    }
Exemplo n.º 58
0
    public static Path3D ReadPath()
    {
        List <Point3D> points = new List <Point3D>();

        using (StreamReader reader = new StreamReader(@"../../paths/paths.txt"))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                string[] pointsString = line.Split(',');
                float    x            = float.Parse(pointsString[0].Trim());
                float    y            = float.Parse(pointsString[1].Trim());
                float    z            = float.Parse(pointsString[2].Trim());
                Point3D  point        = new Point3D(x, y, z);
                points.Add(point);
            }
        }
        Path3D path = new Path3D(points);

        return(path);
    }
Exemplo n.º 59
0
    static void Main()
    {
        Console.WriteLine("StartingPoint : " + Point3D.StartingPoint);
        Point3D a = new Point3D(3, 4, 5);
        Point3D b = new Point3D(-1.3, 2, 5.8);
        Point3D c = new Point3D(0, -4.4, 7);
        Console.WriteLine(a);
        Console.WriteLine(c);

        double distance = DistanceCalculator.CalculateDistanse3D(a, c);
        Console.WriteLine("Distance: " + distance);

        Path3D path = new Path3D(a, c, Point3D.StartingPoint);
        Console.WriteLine("Path: " + path);

        Storage.SavePath("path.txt", path);

        Path3D loadPath = Storage.LoadPaths("path.txt");
        Console.WriteLine("Load path from file: " + loadPath);

    }
Exemplo n.º 60
0
    static void Main()
    {
        List <Point3D> listOfPoints = new List <Point3D>();

        listOfPoints.Add(Point3D.StartingPoint);
        listOfPoints.Add(new Point3D(0, 1, 2));
        listOfPoints.Add(new Point3D(1.5, -3.4));
        listOfPoints.Add(new Point3D(-3.1, 0, 4));

        Path3D path = new Path3D(listOfPoints);

        path.AddPointToPath(new Point3D(0, -1, 1.1111111));
        Console.WriteLine(path);

        string fileLocation = "Path3D.txt";

        Storage.SavePathToFile(fileLocation, path);

        Path3D pathFromFile = Storage.LoadPathFromFile(fileLocation);

        Console.WriteLine(pathFromFile);
    }