Exemplo n.º 1
0
        public async Task <bool> CalculateWholeDataSet(double agleStep)
        {
            try {
                var calculateVector1Task = _fuzzyHelper.CalculateVector(Theta1Min, Theta1Max, agleStep);
                var calculateVector2Task = _fuzzyHelper.CalculateVector(Theta2Min, Theta2Max, agleStep);

                Theta1Vector = await calculateVector1Task;
                Theta2Vector = await calculateVector2Task;

                if (Theta1Vector == null || !Theta1Vector.Any())
                {
                    throw new Exception("Theta1Max Vector is empty.");
                }
                if (Theta2Vector == null || !Theta2Vector.Any())
                {
                    throw new Exception("Theta2Max Vector is empty.");
                }

                AnglesGrid = await _fuzzyHelper.MeshGrid(Theta1Vector, Theta2Vector);

                if (AnglesGrid == null)
                {
                    throw new Exception("MeshGrid function not working");
                }

                var coordinates = await _fuzzyHelper.CalculateCoordinates(L1, L2, AnglesGrid);

                X2D = coordinates.ToArray()[0];
                Y2D = coordinates.ToArray()[1];

                var t1 = Task.Run(() => X.ToList());
                var t2 = Task.Run(() => Y.ToList());

                Task.WaitAll(t1, t2);
                Positions = X.Select((t, i) => new Point {
                    X = t, Y = Y[i], Z = 0
                }).ToList();
                IsDataSetCalculated = true;

                return(true);
            } catch (Exception e) {
                Trace.WriteLine(e);
            }
            return(false);
        }