20 package org.matsim.lanes;
22 import java.awt.geom.Point2D;
23 import java.awt.geom.Point2D.Double;
24 import java.util.List;
60 double horizontalFraction = 0.5 - (lane.getAlignment() / numberOfLinkParts);
61 Point2D.Double laneStart =
calculatePointOnLink(linkData, lane.getStartPosition(), horizontalFraction);
62 Point2D.Double laneEnd =
calculatePointOnLink(linkData, lane.getEndPosition(), horizontalFraction);
63 lane.setStartEndPoint(laneStart, laneEnd);
65 if (lane.getNumberOfLanes() >= 2.0){
66 double noLanesFloor = Math.floor(lane.getNumberOfLanes());
67 double laneOffset = - noLanesFloor / 2 * linkWidthCalculator.
getLaneWidth();
68 if (noLanesFloor % 2 == 0){
69 laneOffset = laneOffset + (linkWidthCalculator.
getLaneWidth()/2);
71 for (
int i = 1; i <= noLanesFloor; i++){
74 lane.addDrivingLane(i, drivingLaneStart, drivingLaneEnd);
75 laneOffset = laneOffset + linkWidthCalculator.
getLaneWidth();
87 public Point2D.Double
calcPoint(Point2D.Double start, Point2D.Double vector,
double distance){
88 double x = start.getX() + (distance * vector.x);
89 double y = start.getY() + (distance * vector.y);
90 return new Point2D.Double(x, y);
96 double endPosition = startPosition + (qlane.
getLength() * linkScale * linkLengthCorrectionFactor);
109 public void connect(Map<String, VisLinkWLanes> otfNetwork){
111 if (otfLink.getLaneData() == null || otfLink.getLaneData().isEmpty()){
112 if (otfLink.getToLinkIds() != null){
113 for (String toLinkId : otfLink.getToLinkIds()){
120 for (
VisLane otfLane : otfLink.getLaneData().values()){
121 if (otfLane.getToLinkIds() != null) {
122 for (String toLinkId : otfLane.getToLinkIds()){
139 Point2D.Double linkStart =
new Point2D.Double(linkStartCoord.
getX(), linkStartCoord.
getY());
140 Point2D.Double linkEnd =
new Point2D.Double(linkEndCoord.
getX(), linkEndCoord.
getY());
143 Point2D.Double deltaLink =
new Point2D.Double(linkEnd.x - linkStart.x, linkEnd.y - linkStart.y);
146 double linkLengthCorrectionFactor = euclideanLinkLength / link.
getLink().
getLength();
147 Point2D.Double deltaLinkNorm =
new Point2D.Double(deltaLink.x / euclideanLinkLength, deltaLink.y / euclideanLinkLength);
148 Point2D.Double normalizedOrthogonal =
new Point2D.Double(deltaLinkNorm.y, - deltaLinkNorm.x);
151 double linkScale = 1.0;
152 if ((euclideanLinkLength * 0.2) > (2.0 * nodeOffsetMeter)){
153 linkScale = (euclideanLinkLength - (2.0 * nodeOffsetMeter)) / euclideanLinkLength;
156 linkScale = euclideanLinkLength * 0.8 / euclideanLinkLength;
161 Point2D.Double scaledLinkEnd = scaledLink.
getSecond();
162 Point2D.Double scaledLinkStart = scaledLink.
getFirst();
172 int maxAlignment = 0;
184 VisLane otfLane = lanesLinkData.
getLaneData().get(lane.getLaneData().getId().toString());
185 if (lane.getToLanes() == null || lane.getToLanes().isEmpty()){
186 for (
Id<Link> id : lane.getLaneData().getToLinkIds()){
192 VisLane otfToLane = lanesLinkData.
getLaneData().get(toLane.getLaneData().getId().toString());
204 return lanesLinkData;
210 return Math.sqrt(Math.pow(deltaLink.x, 2) + Math.pow(deltaLink.y, 2));
void setNormalizedLinkVector(Point2D.Double v)
void setLinkWidth(double linkWidth)
void setEndPosition(double pos)
Point2D.Double getLinkStart()
void addLaneData(VisLane laneData)
Double getLinkOrthogonalVector()
Map< String, VisLane > getLaneData()
VisLane createVisLane(ModelLane qlane, double linkLength, double linkScale, double linkLengthCorrectionFactor)
Point2D.Double calcPoint(Point2D.Double start, Point2D.Double vector, double distance)
static Tuple< Point2D.Double, Point2D.Double > scaleVector(final Point2D.Double start, final Point2D.Double end, double scaleFactor)
double getNumberOfRepresentedLanes()
double calculateLinkWidth(double nrOfLanes)
void setLinkEndCenterPoint(Double linkEndCenter)
double getNumberOfLanes()
void setAlignment(int alignment)
void setStartPosition(double pos)
Point2D.Double calculatePointOnLink(final VisLinkWLanes laneLinkData, final double position, final double horizontalFraction)
void setNumberOfLanes(double nrLanes)
double getStartsAtMeterFromLinkEnd()
int getMaximalAlignment()
void setLinkStartEndPoint(Double linkStart, Double linkEnd)
double getNumberOfLanes()
List< ModelLane > getToLanes()
void addToLink(VisLinkWLanes link)
void addToLinkId(String toLinkId)
void setLinkOrthogonalVector(Point2D.Double v)
Double getNormalizedLinkVector()
void addToLinkId(String toLinkId)
void setNumberOfLanes(double noLanes)
void connect(Map< String, VisLinkWLanes > otfNetwork)
void addToLane(VisLane toLane)
VisLinkWLanes createVisLinkLanes(CoordinateTransformation transform, VisLink link, double nodeOffsetMeter, List< ModelLane > lanes)
Map< Id< Link >, ? extends Link > getOutLinks()
double calculateEuclideanLinkLength(Point2D.Double deltaLink)
Point2D.Double getLinkEnd()
void setMaximalAlignment(int maxAlign)
void setLinkStartCenterPoint(Double linkStartCenter)
void recalculatePositions(VisLinkWLanes linkData, SnapshotLinkWidthCalculator linkWidthCalculator)