1 package org.matsim.vis.snapshotwriters;
10 import static java.util.Objects.requireNonNull;
26 private static final double TWO_PI = 2.0 * Math.PI;
27 private static final double PI_HALF = Math.PI / 2.0;
103 return "PositionInfo; agentId: " + this.agentId.toString()
104 +
" easting: " + this.easting
163 return new PositionInfo(personId, linkId, vehicleId, easting, northing, colorValue, agentState, null, userDefined);
188 this.linkWidthCalculator = linkWidthCalculator;
218 this.fromCoord = fromCoord;
223 this.toCoord = toCoord;
228 this.linkLength = linkLength;
238 this.distanceOnLink = distanceOnLink;
254 requireNonNull(this.linkWidthCalculator);
255 requireNonNull(fromCoord);
256 requireNonNull(toCoord);
258 var theta = calculateTheta(this.fromCoord, this.toCoord);
260 var correction = calculateCorrection(euclideanLength, this.linkLength);
261 var lanePosition = linkWidthCalculator.calculateLanePosition(lane);
262 var easting = fromCoord.
getX()
263 + (Math.cos(theta) * distanceOnLink * correction)
264 + (Math.sin(theta) * lanePosition);
265 var northing = fromCoord.
getY()
266 + Math.sin(theta) * distanceOnLink * correction
267 - Math.cos(theta) * lanePosition;
270 this.agentId, this.linkId, this.vehicleId,
272 colorValue, agentState, drivingState, user);
277 double dx = -startCoord.
getX() + endCoord.
getX();
278 double dy = -startCoord.
getY() + endCoord.
getY();
281 theta = Math.atan(dy / dx);
283 theta = Math.PI + Math.atan(dy / dx);
290 theta = 0.833 * Math.PI;
293 if (theta < 0.0) theta +=
TWO_PI;
299 return curvedLength != 0 ? euclideanLength / curvedLength : 0;
LinkBasedBuilder setVehicleId(Id< Vehicle > vehicleId)
LinkBasedBuilder setToCoord(Coord toCoord)
DirectBuilder setColorValue(double colorValue)
static double calcEuclideanDistance(Coord coord, Coord other)
SnapshotLinkWidthCalculator linkWidthCalculator
final AgentState getAgentState()
final Id< Vehicle > vehicleId
LinkBasedBuilder setUser(int user)
static final double TWO_PI
LinkBasedBuilder setColorValue(double colorValue)
LinkBasedBuilder setAgentState(AgentSnapshotInfo.AgentState agentState)
DirectBuilder setLinkId(Id< Link > id)
final double getEasting()
DirectBuilder setPersonId(Id< Person > personId)
double calculateCorrection(double euclideanLength, double curvedLength)
AgentSnapshotInfo build()
final Id< Person > getId()
PositionInfo(Id< Person > agentId, Id< Link > linkId, Id< Vehicle > vehicleId, double easting, double northing, double colorValue, AgentState agentState, DrivingState drivingState, int user)
LinkBasedBuilder setLinkWidthCalculator(SnapshotLinkWidthCalculator linkWidthCalculator)
LinkBasedBuilder setDistanceOnLink(double distanceOnLink)
final DrivingState getDrivingState()
LinkBasedBuilder setPersonId(Id< Person > personId)
LinkBasedBuilder setLane(int lane)
final Id< Person > agentId
LinkBasedBuilder setLinkId(Id< Link > linkId)
final double getNorthing()
DirectBuilder setAgentState(AgentState agentState)
final Id< Link > getLinkId()
DirectBuilder setNorthing(double northing)
final Id< Vehicle > getVehicleId()
AgentSnapshotInfo build()
DirectBuilder setEasting(double easting)
static final double PI_HALF
final AgentState agentState
final double getColorValueBetweenZeroAndOne()
DirectBuilder setVehicleId(Id< Vehicle > id)
double calculateTheta(Coord startCoord, Coord endCoord)
final DrivingState drivingState
DirectBuilder setUserDefined(int userDefined)
LinkBasedBuilder setFromCoord(Coord fromCoord)
final double getAzimuth()
LinkBasedBuilder setLinkLength(double linkLength)
LinkBasedBuilder setDrivingState(AgentSnapshotInfo.DrivingState drivingState)