/** * returns the euclidean distance between two points (x1,y1) and (x2,y2) */ public static double getEuclideanDistance(double x1, double y1, double x2, double y2){ return getEuclideanDistance(new Coord(x1,y1), new Coord(x2, y2)); }
/** * This method expects the nearest link to a given measure point. * It calculates the euclidean distance for both nodes of the link, * "fromNode" and "toNode" and returns the node with shorter distance */ public static Node getCloserNodeOnLink(Coord coord, Link link) { // yyyy I don't think there is a test for this anywhere. kai, mar'14 Node toNode = link.getToNode(); Node fromNode= link.getFromNode(); double distanceToNode = getEuclideanDistance(coord, toNode.getCoord()); double distanceFromNode= getEuclideanDistance(coord, fromNode.getCoord()); if(distanceToNode < distanceFromNode) return toNode; return fromNode; }
final Coord arCoord = arfac.getCoord(); double dist = NetworkUtils.getEuclideanDistance( dpCoord, arCoord ) ; double travelTimeTmp = dist / speed ;
/** * This method calculates the distance between a point and a node via a link (which should contains * the node) as the sum of * <ul> * <li> the orthogonal distance between the point and the link and * <li> the distance between the intersection point of the orthogonal * projection (from the point to the link) to the node. * </ul> * If the orthogonal projection of the point to the line does not intersects the link, the method * returns the Euclidean distance between the point and the node. */ public static Distances getDistances2NodeViaGivenLink(Coord coord, Link link, Node destinationNode){ Coord intersection = CoordUtils.orthogonalProjectionOnLineSegment(link.getFromNode().getCoord(), link.getToNode().getCoord(), coord); Distances distances = new Distances(); double distanceCoord2Intersection = NetworkUtils.getEuclideanDistance(coord, intersection); double distanceIntersection2Node = NetworkUtils.getEuclideanDistance(intersection, destinationNode.getCoord()); distances.setDistanceCoord2Intersection(distanceCoord2Intersection); distances.setDistanceIntersetion2Node(distanceIntersection2Node); return distances; } }
double distance_m = NetworkUtils.getEuclideanDistance(opportunity.getCoord(), nearestNode.getCoord());
double dist = Double.POSITIVE_INFINITY; for (TransitStopFacility possibleFromStop : fromTransitStops.keySet()){ // an alternative would be to get the transfer stops at _toTransitStop_ and match with fromStops. Amit Jan'18 double tempDist = NetworkUtils.getEuclideanDistance(possibleFromStop.getCoord().getX(), possibleFromStop.getCoord().getY(), toTransitStop.getCoord().getX(), toTransitStop.getCoord().getY()); if (tempDist < dist) { dist = tempDist;
private Leg createAccessTransitWalkLeg(Coord fromCoord, RouteSegment routeSegement) { Leg leg = this.createTransitWalkLeg(fromCoord, routeSegement.fromStop.getCoord()); Route walkRoute = RouteUtils.createGenericRouteImpl(null, routeSegement.fromStop.getLinkId()); walkRoute.setTravelTime(leg.getTravelTime() ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(fromCoord, routeSegement.fromStop.getCoord())); leg.setRoute(walkRoute); return leg; }
private Leg createEgressTransitWalkLeg(RouteSegment routeSegement, Coord toCoord) { Leg leg = this.createTransitWalkLeg(routeSegement.toStop.getCoord(), toCoord); Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.toStop.getLinkId(), null); walkRoute.setTravelTime(leg.getTravelTime() ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.toStop.getCoord(), toCoord)); leg.setRoute(walkRoute); return leg; }
private Leg createTransferTransitWalkLeg(RouteSegment routeSegement) { Leg leg = this.createTransitWalkLeg(routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()); Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.getFromStop().getLinkId(), routeSegement.getToStop().getLinkId()); // walkRoute.setTravelTime(leg.getTravelTime() ); // transit walk leg should include additional transfer time; Amit, Aug'17 leg.setTravelTime( getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); walkRoute.setTravelTime(getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.fromStop.getCoord(), routeSegement.toStop.getCoord())); leg.setRoute(walkRoute); return leg; }