예제 #1
0
        protected override DrivingLane CalculateDrivingLane(Point _point1, Point _point2, int _thisLane)
        {
            Console.WriteLine("STARTPOINTS : {0} -- {1},   {2}", _point1, _point2, this.dir);

            List <LanePoints> _lanePoints = new List <LanePoints>();
            Point             _normpoint1 = _point1; Point _normpoint2 = _point2;

            /*
             * if (this.dir == "N" || this.dir == "S")
             * {
             *  _normpoint1 = new Point(_point1.X - this.roadwidth, _point1.Y);
             *  _normpoint2 = new Point(_point2.X + this.roadwidth, _point2.Y);
             * }
             * else if (dir == "E" || this.dir == "W")
             * {
             *  _normpoint1 = new Point(_point1.Y - this.roadwidth, _point1.X);
             *  _normpoint2 = new Point(_point2.Y + this.roadwidth, _point2.X);
             * } */


            Tuple <int, int> _dir  = GetDirection(_normpoint1, _normpoint2);
            Point            _prev = _normpoint1;
            int temp = 0;

            while (Math.Abs(_normpoint1.X - _normpoint2.X) > 0 || Math.Abs(_normpoint1.Y - _normpoint2.Y) > 0)
            {
                temp++;

                Console.WriteLine("{0} -- {1}", _normpoint1, _normpoint2);
                _normpoint1 = new Point(_normpoint1.X - _dir.Item1, _normpoint1.Y - _dir.Item2);

                _lanePoints.Add(new LanePoints(_normpoint1, AbstractRoad.CalculateAngle(_prev, _normpoint1)));

                _prev = _normpoint1;

                if (temp > 500)
                {
                    break;
                }
            }

            return(new DrivingLane(_lanePoints, this.dir, lanes, _thisLane));

            foreach (LanePoints x in _lanePoints)
            {
                Log.Write(x.ToString());
            }
        }
예제 #2
0
        protected override DrivingLane CalculateDrivingLane(Point _point1, Point _point2, int _thisLane)
        {
            Console.WriteLine("{0} --- {1}", _point1, _point2);


            List <LanePoints> _lanePoints = new List <LanePoints>();
            Point             _normpoint1 = _point1; Point _normpoint2 = _point2;

            Tuple <int, int> _dir = GetDirection(_point1, _point2);

            Console.WriteLine(dir);

            Point _prev = _normpoint1;
            Point _nulpoint;

            if (dir == "NE")
            {
                _nulpoint = new Point(Math.Max(_point1.X, _point2.X), Math.Min(_point1.Y, _point2.Y));
            }
            else if (dir == "NW")
            {
                _nulpoint = new Point(Math.Min(_point1.X, _point2.X), Math.Min(_point1.Y, _point2.Y));
            }
            else if (dir == "SW")
            {
                _nulpoint = new Point(Math.Min(_point1.X, _point2.X), Math.Max(_point1.Y, _point2.Y));
            }
            else // (dir == "SE")
            {
                _nulpoint = new Point(Math.Max(_point1.X, point2.X), Math.Max(_point1.Y, point2.Y));
            }

            int _deltaX = Math.Abs(_point1.X - _point2.X);
            int _deltaY = Math.Abs(_point1.Y - _point2.Y);
            int _Ytemp  = 0;
            int _Xtemp  = 0;
            int _ytemp  = 0;
            int _xtemp  = 0;

            Console.WriteLine(_nulpoint);

            for (int x = 0, y = 0; x <= _deltaX || y <= _deltaY; x++, y++)
            {
                if ((x >= _deltaX && y >= _deltaY) || _prev == _point2)
                {
                    break;
                }

                _Xtemp = _point1.X + x * _dir.Item1;
                _ytemp = _point1.Y + y * _dir.Item2;

                if ((dir == "NE" || dir == "NW") && x <= _deltaX)
                {
                    _Ytemp = _nulpoint.Y + (int)Math.Sqrt(Math.Pow(_deltaY, 2) * (1 - (Math.Pow(_Xtemp - _nulpoint.X, 2) / Math.Pow(_deltaX, 2))));
                }
                else if ((dir == "SE" || dir == "SW") && x <= _deltaX)
                {
                    _Ytemp = _nulpoint.Y - (int)Math.Sqrt(Math.Pow(_deltaY, 2) * (1 - (Math.Pow(_Xtemp - _nulpoint.X, 2) / Math.Pow(_deltaX, 2))));
                }
                if ((dir == "NE" || dir == "NW") && y <= _deltaY)
                {
                    _xtemp = _nulpoint.X + (int)Math.Sqrt(Math.Pow(_deltaX, 2) * (1 - (Math.Pow(_ytemp - _nulpoint.Y, 2) / Math.Pow(_deltaY, 2))));
                }
                else if ((dir == "SE" || dir == "SW") && y <= _deltaY)
                {
                    _xtemp = _nulpoint.X - (int)Math.Sqrt(Math.Pow(_deltaX, 2) * (1 - (Math.Pow(_ytemp - _nulpoint.Y, 2) / Math.Pow(_deltaY, 2))));
                }

                if (Math.Sqrt(Math.Pow(Math.Abs(_prev.X - _Xtemp), 2) + Math.Pow(Math.Abs(_prev.Y - _Ytemp), 2)) <= Math.Sqrt(Math.Pow(Math.Abs(_prev.X - _xtemp), 2) + Math.Pow(Math.Abs(_prev.Y - _ytemp), 2)))
                {
                    _normpoint1 = new Point(_Xtemp, _Ytemp);
                }
                else
                {
                    _normpoint1 = new Point(_xtemp, _ytemp);
                }


                _lanePoints.Add(new LanePoints(_normpoint1, AbstractRoad.CalculateAngle(_prev, _normpoint1)));

                _prev = _normpoint1;
            }

            foreach (LanePoints x in _lanePoints)
            {
                Console.WriteLine(x.ToString());
            }

            return(new DrivingLane(_lanePoints, this.dir, lanes, _thisLane));
        }
예제 #3
0
 public RoadTestForm()
 {
     Test        = new DiagonalRoad(new Point(20, 20), new Point(220, 220), 2, "S"); //TEMP OM TE TESTEN
     this.Paint += Drawing;
 }
예제 #4
0
        protected override DrivingLane CalculateDrivingLane(Point _point1, Point _point2, int _thisLane)
        {
            List <LanePoints> _lanePoints = new List <LanePoints>();
            Point             _normpoint1 = _point1; Point _normpoint2 = _point2;
            double            _rc;
            Point             _prev = _normpoint1;
            bool divByZero = false;

            _rc = (double)(_point2.Y - _point1.Y) / (double)(_point2.X - _point1.X);
            if (_point2.X - _point1.X == 0)
            {
                _rc = 0;
                int _vertical;
                divByZero = true;
                if (_point1.Y > _point2.Y)
                {
                    _vertical = -1;
                }
                else
                {
                    _vertical = 1;
                }

                for (int y = 0; y <= Math.Abs(_point1.Y - _point2.Y); y++)
                {
                    _normpoint1 = new Point(_point1.X, (int)(_point1.Y + y * _vertical));
                    _lanePoints.Add(new LanePoints(_normpoint1, AbstractRoad.CalculateAngle(_prev, _normpoint1)));

                    _prev = _normpoint1;
                }
            }
            Console.WriteLine(_rc);

            int _dir = GetDirection(_point1, _point2);

            /*if (_rc >= 0.5 || _point2.X - _point1.X == 0)
             * {
             *  for (int y = 0; y <= Math.Abs(_point1.Y - _point2.Y); y++)
             *  {
             *      _normpoint1 = new Point(_point1.X + y/_rc * _dir, (int)(_point1.Y + y * _rc * _dir));
             *      _lanePoints.Add(new LanePoints(_normpoint1, AbstractRoad.CalculateAngle(_prev, _normpoint1)));
             *
             *      _prev = _normpoint1;
             *  }
             * }*/

            for (int x = 0; x <= Math.Abs(_point1.X - _point2.X) && !divByZero; x++)
            {
                _normpoint1 = new Point(_point1.X + x * _dir, (int)(_point1.Y + x * _rc * _dir));
                _lanePoints.Add(new LanePoints(_normpoint1, AbstractRoad.CalculateAngle(_prev, _normpoint1)));

                _prev = _normpoint1;
            }


            foreach (LanePoints x in _lanePoints)
            {
                Console.WriteLine(x.ToString());
            }

            return(new DrivingLane(_lanePoints, this.dir, lanes, _thisLane));
        }