Beispiel #1
0
        private List <RectangularObstacle> segmentSplineByX(SplineObstacle obstacle, Polynom poly, int obstaclePassDistance)
        {
            RealCoordinate current = new RealCoordinate(obstacle.points[0].x, obstacle.points[0].y - obstaclePassDistance);
            RealCoordinate end     = new RealCoordinate(obstacle.points[obstacle.points.Count - 1].x,
                                                        obstacle.points[obstacle.points.Count - 1].y);
            List <RectangularObstacle> obstacles     = new List <RectangularObstacle>();
            RectangularObstacle        firstObstacle = new RectangularObstacle(2 * obstaclePassDistance, obstaclePassDistance,
                                                                               new RealCoordinate(current.x - obstaclePassDistance, current.y - obstaclePassDistance));

            obstacles.Add(firstObstacle);
            do
            {
                RectangularObstacle rect = new RectangularObstacle(2 * obstaclePassDistance, 2,
                                                                   new RealCoordinate(current.x, current.y));
                obstacles.Add(rect);
                if (current.x + 2 <= end.x)
                {
                    current.x += 2;
                    current.y  = poly.getPolynomValue(current.x) - obstaclePassDistance;
                }
                else
                {
                    current.x = end.x;
                    current.y = end.y;
                }
            } while (RealCoordinate.getDistanceBetweenCoordinates(current, end) != 0);
            RectangularObstacle lastObstacle = new RectangularObstacle(2 * obstaclePassDistance, obstaclePassDistance,
                                                                       new RealCoordinate(current.x, current.y));

            obstacles.Add(lastObstacle);

            return(obstacles);
        }
 private void drawSplineObstacle(SplineObstacle o)
 {
     Coordinate[] relLocs = new Coordinate[o.points.Count];
     for (int i = 0; i < o.points.Count; i++)
     {
         Coordinate c = calculateRelativeCanvasPosition(o.points[i]);
         relLocs[i] = c;
     }
     graphicsObj.DrawCurve(obstaclePen, relLocs.Select(item => new Point(item.x, item.y)).ToArray());
 }
Beispiel #3
0
        public List <RectangularObstacle> handleSplineObstacle(SplineObstacle obstacle, int obstaclePassDistance)
        {
            double[] x = obstacle.points.Select(item => (double)item.x).ToArray();
            double[] y = obstacle.points.Select(item => (double)item.y).ToArray();

            double[] coeficients  = Polyfit(x, y, obstacle.points.Count - 1).Reverse().ToArray();
            bool     functionFlag = false;

            if (isFunctionByY(coeficients))
            {
                coeficients  = Polyfit(y, x, obstacle.points.Count - 1).Reverse().ToArray();
                functionFlag = true;
            }
            Polynom poly = new Polynom(coeficients, functionFlag);

            if (functionFlag == false)
            {
                return(segmentSplineByX(obstacle, poly, obstaclePassDistance));
            }
            else
            {
                return(segmentSplineByY(obstacle, poly, obstaclePassDistance));
            }
        }