PUPoints.java


Below is the syntax highlighted version of PUPoints.java.


/*
 *  Christopher Moretti
 *  cmoretti
 *  P01A / P06
 * 
 *  takes map filename on CL
 *  reads lat/lon coordinates from StdIn
 *  prints "map coordinates" to StdOut
 *  draws points on StdDraw
 * 
 *  Dependencies: StdIn, StdOut, StdDraw
 */
public class PUPoints {
    
    public static void main(String[] args) {
        
        // map filename
        String PHOTO = args[0];
    
        // map extremes
        double minX = -74.66443;
        double minY = 40.33855;
        double maxX = -74.64564;
        double maxY = 40.35281;

        // set scale from 0->1 in both dimensions
        // and draw picture centered and scaled.
        StdDraw.setXscale(0, 1);
        StdDraw.setYscale(0, 1);
        StdDraw.picture(.5, .5, PHOTO, 1, 1);

        // read in all lat/lons from StdIn
        while(!StdIn.isEmpty()) {
            double y = StdIn.readDouble();
            double x = StdIn.readDouble();

            // scale lat/lon to 0-1
            double yCoord = (y - minY)*(1/(maxY-minY));
            double xCoord = (x - minX)*(1/(maxX-minX));

            // print the point and draw it.
            StdOut.println(yCoord+" "+xCoord);
            StdDraw.circle(xCoord, yCoord, .01);
        }

        StdDraw.show();
    }
}