Example #1
0
 public Connection(Bezier bezier, Lane startlane, Lane endlane, int startbezierindex, int endbezierindex,
                   double starttimeindex, double endtimeindex, double unspawnindex = double.NaN)
 {
     Bezier = bezier;
     StartLane = startlane;
     EndLane = endlane;
     StartBezierIndex = startbezierindex;
     EndBezierIndex = endbezierindex;
     StartTime = starttimeindex;
     EndTime = endtimeindex;
     UnSpawnTimeIndex = unspawnindex;
 }
        //[OptionalField] private RoadLane nextlane;
        //[OptionalField] private RoadLane previouslane;
        public CrossingLane(Crossing crossing, Lane previouslane, Lane nextlane, double width, List<Vehicle> vehiclelist)
        {
            int colorindex;

            if (previouslane.LaneDirection == LaneDirection.Forward)
                colorindex = previouslane.LaneIndex;
            else
                colorindex = -previouslane.LaneIndex - 1;

            Crossing = crossing;
            curvecolor = Colors.GetSaturatedColor(colorindex);
            ILaneContainer = crossing;
            LaneIndex = nextlane.LaneIndex;
            Width = width;
            this.vehiclelist = vehiclelist;

            nextlanes.Add(nextlane);
            nextlane.AddPreviousLane(this);
            previouslanes.Add(previouslane);
            previouslane.AddNextLane(this);

            PointD point1 = previouslane.GetLastCoordinate();
            PointD point2 = nextlane.GetFirstCoordinate();

            VectorD vector1 = previouslane.GetLastVelocity();
            VectorD vector2 = nextlane.GetFirstVelocity();
            VectorD vector3 = vector1.GetUnitVector()*new VectorD(point1, point2).Length/3;

            if (vector1.IsCoLinearWith(vector2))
                // Als de in en uitgaande RoadLane van de die deze CrossingLane verbindt dezelfde richting hebben
                // If the incoming and outgoing RoadLane that this crossinglane connects have the same direction
                // we need a third order curve
                beziers = new Bezier[] {new CubicBezier(point1, point1 + vector3, point2 - vector3, point2)};
            else // else a second order
                beziers = new Bezier[]
                    {
                        new QuadraticBezier(point1,
                                            new LineD(point1, vector1).GetCrossingPoint(new LineD(point2,
                                                                                                  vector2)),
                                            point2)
                    };

            Length = beziers.Sum(bezier => bezier.Length);
        }
Example #3
0
        public Connection(Lane startlane, Lane endlane, PointD location, VectorD beginvelocity, int bezierindex,
                          double bezierfactor, double speed, double time)
        {
            StartLane = startlane;
            EndLane = endlane;

            StartBezierIndex = bezierindex;
            StartTime = time;
            EndBezierIndex = bezierindex;
            EndTime = time + 2*bezierfactor;
            UnSpawnTimeIndex = double.NaN;

            // This part is of importance when a lanechange occurs while the Vehicle changes Bezier.
            // This doesn't occur in the current build.
            if (EndTime > 1)
            {
                if (EndBezierIndex == endlane.Beziers.Length - 1)
                    UnSpawnTimeIndex = 0.5F;
                else
                {
                    EndTime -= 1;
                    EndTime /= bezierfactor;
                    EndTime *= speed/startlane.Beziers[EndBezierIndex].Length;
                    EndBezierIndex++;
                }
            }

            // Get velocity on the desired endpoint.
            VectorD endvelocity = endlane.Beziers[EndBezierIndex].GetVelocity(EndTime);

            // Set the Bézier curve.
            PointD p0 = location;
            PointD p1 = location + 2*speed*beginvelocity/(3*beginvelocity.Length);
            PointD p3 = endlane.Beziers[EndBezierIndex].GetCoordinate(EndTime);
            PointD p2 = p3 - 2*speed*endvelocity/(3*endvelocity.Length);

            Bezier = new CubicBezier(p0, p1, p2, p3);
        }
Example #4
0
        protected void setlane(Lane lane, bool changeilanecontainer)
        {
            // This methods sets a lane. This isn't accomplished by property because of intended side-effects:
            // Crossinglane and roadlane also get changed. We save these two to not always have to cast in case
            // we want to know if Vehicle is on a crossinglane or roadlane.

            if (this.lane == lane)
                return;

            // Remove the Vehicle from the Vehiclelist of Lane. If ChangeIlaneContainer, then also remove Vehicle from the
            // IlaneContainer of the Lane.
            if (this.lane != null)
                this.lane.LeaveLane(this, changeilanecontainer);

            crossinglane = lane as CrossingLane;
            this.lane = lane;
            roadlane = lane as RoadLane;

            trafficlight = roadlane == null ? null : roadlane.TrafficLight;

            if (this.lane != null)
                this.lane.EnterLane(this);
        }
Example #5
0
 public bool BelongsToSameILaneContainer(Lane lane)
 {
     return ILaneContainer == lane.ILaneContainer;
 }
Example #6
0
 public void AddPreviousLane(Lane nextlane)
 {
     previouslanes.Add(nextlane);
 }
Example #7
0
 public void AddNextLane(Lane nextlane)
 {
     nextlanes.Add(nextlane);
 }
 public void AddExitLane(Lane lane)
 {
     exitlanes.Add(lane);
 }
 public TrafficLight(Lane entrylane, PointD location)
 {
     this.entrylane = entrylane;
     this.location = location;
     exitlanes = new List<Lane>();
 }