Java Code Examples for org.matsim.api.core.v01.Coord#getX()

The following examples show how to use org.matsim.api.core.v01.Coord#getX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoordTools.java    From pt2matsim with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the maximum x and y values of the stop coordinates.
 * @return Array of Coords with the minimal South-West and the
 * 		   maximal North-East Coordinates
 */
public static Coord[] getExtent(TransitRoute transitRoute) {
	double maxE = 0;
	double maxN = 0;
	double minS = Double.MAX_VALUE;
	double minW = Double.MAX_VALUE;

	for(TransitRouteStop trs : transitRoute.getStops()) {
		Coord c = trs.getStopFacility().getCoord();
		if(c.getX() > maxE) {
			maxE = c.getX();
		}
		if(c.getY() > maxN) {
			maxN = c.getY();
		}
		if(c.getX() < minW) {
			minW = c.getX();
		}
		if(c.getY() < minS) {
			minS = c.getY();
		}
	}
	return new Coord[]{new Coord(minW, minS), new Coord(maxE, maxN)};
}
 
Example 2
Source File: GtfsShape.java    From pt2matsim with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds a new point
 */
@Override
public void addPoint(Coord point, int pos) {
	Coord check = coordSorted.put(pos, point);

	if(check != null && (check.getX() != point.getX() || check.getY() != point.getY())) {
		throw new IllegalArgumentException("Sequence position " + pos + " already defined in shape " + id);
	}

	if(point.getX() < extentSWx) {
		extentSWx = point.getX();
	}
	if(point.getY() < extentSWy) {
		extentSWy = point.getY();
	}
	if(point.getX() > extentNEx) {
		extentNEx = point.getX();
	}
	if(point.getY() > extentNEy) {
		extentNEy = point.getY();
	}
}
 
Example 3
Source File: CoordTools.java    From pt2matsim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return the azimuth in [rad] of a line defined by two points. A line going north has
 * azimuth 0, a line going east has az=pi/2, a line going west az=1.5*pi
 */
public static double getAzimuth(Coord from, Coord to) {
	double deltaE = to.getX()-from.getX();
	double deltaN = to.getY()-from.getY();

	double az2 = Math.atan2(deltaE, deltaN);

	if(az2 < 0)
		az2 = az2+2*Math.PI;

	if(az2 >= 2*Math.PI)
		az2 = az2-2*Math.PI;

	return az2;
}
 
Example 4
Source File: CoordTools.java    From pt2matsim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return Returns the point on the line between lineStart and lineEnd which
 * is closest to refPoint.
 */
public static Coord getClosestPointOnLine(Coord lineStart, Coord lineEnd, Coord refPoint) {
	double azLine = getAzimuth(lineStart, lineEnd);
	double azPoint = getAzimuth(lineStart, refPoint);
	double azDiff = (azLine > azPoint ? azLine-azPoint : azPoint-azLine);

	double distanceToNewPoint = Math.cos(azDiff) * CoordUtils.calcEuclideanDistance(lineStart, refPoint);

	// assuming precision < 1 mm is not needed
	double newN = lineStart.getY() + Math.round(Math.cos(azLine) * distanceToNewPoint * 1000) / 1000.;
	double newE = lineStart.getX() + Math.round(Math.sin(azLine) * distanceToNewPoint * 1000) / 1000.;

	return new Coord(newE, newN);
}
 
Example 5
Source File: CoordTools.java    From pt2matsim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates a new Coordinate given the original point, azimuth and distance.
 */
public static Coord calcNewPoint(Coord fromPoint, double azimuth, double distance) {
	double dE = Math.sin(azimuth)*distance;
	double dN = Math.cos(azimuth)*distance;

	return new Coord(fromPoint.getX()+dE, fromPoint.getY()+dN);
}
 
Example 6
Source File: ShapeToolsTest.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
private static Coord offset(Coord c) {
	return new Coord(c.getX() + offset, c.getY() + offset);
}
 
Example 7
Source File: CoordTools.java    From pt2matsim with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Checks if a coordinate is in the area given by sw and ne.
 * @param coord the coordinate to check
 * @param sw the south-west corner of the area
 * @param ne the north-east corner of the area
 */
public static boolean isInArea(Coord coord, Coord sw, Coord ne) {
	if(coord.getX() < sw.getX() || coord.getY() < sw.getY()) return false;
	return !(coord.getX() > ne.getX() || coord.getY() > ne.getY());
}