Beispiel #1
0
        public void setdestendofroad() //calcmobilepointendofroad should be replaced by this app at some point
        {
            double bias;               // 'for direction
            int    side;

            if (destination01 == 1)
            {
                bias = 0;
            }
            else
            {
                bias = Math.PI;
            }

            side          = global.CarSide == carsidet.Right ? 1 : -1;
            destination.x = roadon.points[destination01].x +
                            roadon.points[destination01].crossingradius *
                            Math.Cos(roadon.direction + bias + Math.PI) +
                            (lane + 1) * roadon.roadlanewidth *
                            Math.Cos(roadon.direction + bias + side * Math.PI / 2);
            destination.y = roadon.points[destination01].y +
                            roadon.points[destination01].crossingradius *
                            Math.Sin(roadon.direction + bias + Math.PI) +
                            (lane + 1) * roadon.roadlanewidth *
                            Math.Sin(roadon.direction + bias + side * Math.PI / 2);
            updatedirection();
            atdestination = false;
        }
Beispiel #2
0
        //Methods
        public car(double aspeed, double adt, point alocation,
                   point adestination, road aroadon, int adestination01,
                   double abreakacceleration)
        {
            speed          = aspeed;
            preferredspeed = speed;
            dt             = adt;
            calcdeltalocation();

            location = alocation;

            destination = new point(0, 0);
            newdestination(adestination, aroadon, adestination01);
            atdestination = false;

            breakacceleration = abreakacceleration;
            calcbreakdistance();
            mode               = carmode.Normal;
            ontrajectory       = false;
            side               = global.DefaultCarSide;
            distancecontroller = new pidcontroller(global.KDistanceController, global.IDistanceController, 0,
                                                   global.MinCarSpeed, global.MaxCarSpeed);
            speedcontroller = new pidcontroller(global.KSpeedController, global.ISpeedController, 0,
                                                global.MinCarSpeed, global.MaxCarSpeed);
            speedcontroller.direction = global.Reverse;
            speedcontroller.init(preferredspeed, speed, speed);
            maxspeed           = global.MaxCarSpeed;
            wlangle            = Math.Atan(global.CarWidth / global.CarLength);
            cardiag            = Math.Sqrt(Math.Pow(global.CarWidth, 2) + Math.Pow(global.CarLength, 2)) / 2 * global.GScale;
            cardiagkm          = Math.Sqrt(Math.Pow(global.CarWidth, 2) + Math.Pow(global.CarLength, 2)) / 2;
            highlighted        = false;
            decisiont          = decisiontype.RandomDecision;
            buildingfrom       = 0;
            buildingto         = 1;
            route              = new List <int>(0);
            currentstepinroute = 0;
            lane           = 0;
            changinglanes  = false;
            cartobedeleted = false;
            newroadn       = 0;

            timetotargetspeed = 50 * global.PSpeedController / global.SampleT;
            carcolour         = global.CarColour;
            cartype           = cartypes.OtherCar;
        }
Beispiel #3
0
        public void lanechange(int deltachange) //deltachange is the change in the lane number
        //that the car will be in
        {
            int side;

            side = global.CarSide == carsidet.Right ? 1 : -1;
            double distanceduringlanechange = speed * global.TimeToChangeLane;
            double anglechange      = Math.Asin(deltachange * roadon.roadlanewidth / distanceduringlanechange) * side;
            double distanceparallel = Math.Cos(Math.Abs(anglechange)) * distanceduringlanechange;

            if (utilities.distance(destination, location) >= distanceparallel)
            {
                direction    += anglechange;
                destination.x = location.x + distanceduringlanechange * Math.Cos(direction + anglechange);
                destination.y = location.y + distanceduringlanechange * Math.Sin(direction + anglechange);
                updatedirection();
                changinglanes = true;
            }
        }