src/com/wherehoo/WHPolygon.java
/**
     * Calculate the heading from a location described by <tt>origin</tt> to this <tt>WHPolygon</tt>.  
     * @param origin some point on the Earth
     * @return Heading, an angle between a meridian passing through <tt>origin</tt> 
     * and a line from <tt>origin</tt> to this <tt>WHPolygon</tt>.
     */
Calculate the heading from a location described by origin to this WHPolygon.
@param origin some point on the Earth
@return Heading, an angle between a meridian passing through origin
and a line from origin to this WHPolygon.
Calculate the heading from a location described by origin to this WHPolygon . @param origin some point on the Earth @return Heading an angle between a meridian passing through origin and a line from origin to this WHPolygon .
public double heading(Point2D.Double origin){
	if (coordinates.length == 1){
	    return WHGeo.heading(origin, coordinates[0]);
	} else {
	    if (this.contains(origin)){
		return 0;
	    } else {
		double d=WHGeo.distance(origin, new Line2D.Double(coordinates[coordinates.length-1],coordinates[0]));
		Line2D.Double closest_side = new Line2D.Double(coordinates[coordinates.length-1],coordinates[0]);
		double temp_d;
		for (int i=1;i<coordinates.length;i++){
		    temp_d=WHGeo.distance(origin, new Line2D.Double(coordinates[i-1],coordinates[i]));
		    if (temp_d<d){
			d=temp_d;
			closest_side=new Line2D.Double(coordinates[i-1],coordinates[i]);
		    }
		}
		return WHGeo.heading(origin, closest_side);
	    }
	}
    }
public double heading ( Point2D . Double origin ) { if ( coordinates . length == 1 ) { return WHGeo . heading ( origin , coordinates [ 0 ] ) ; } else { if ( this . contains ( origin ) ) { return 0 ; } else { double d = WHGeo . distance ( origin , new Line2D . Double ( coordinates [ coordinates . length - 1 ] , coordinates [ 0 ] ) ) ; Line2D . Double closest_side = new Line2D . Double ( coordinates [ coordinates . length - 1 ] , coordinates [ 0 ] ) ; double temp_d ; for ( int i = 1 ; i < coordinates . length ; i ++ ) { temp_d = WHGeo . distance ( origin , new Line2D . Double ( coordinates [ i - 1 ] , coordinates [ i ] ) ) ; if ( temp_d < d ) { d = temp_d ; closest_side = new Line2D . Double ( coordinates [ i - 1 ] , coordinates [ i ] ) ; } } return WHGeo . heading ( origin , closest_side ) ; } } }
Calculate the heading from a location described by <tt>origin</tt> to this <tt>WHPolygon</tt>.
Calculate the heading from a location described by <tt > origin< / tt > to this <tt > WHPolygon< / tt > .
//if this WHPolygon has one vertex => return the heading to that vertex
 //if origin inside this WHPolygon => return 0
 //find the closest side
 //System.out.println("Closest side: "+closest_side.getX1()+","+closest_side.getY1()+","+closest_side.getX2()+","+closest_side.getY2());
