src/com/wherehoo/WHGeo.java
/**
     * Calculates the distance between <tt>origin</tt> and <tt>end</tt>. 
     *@param origin start point
     *@param end end point
     *@return Geographicaldistance between <tt>origin</tt> and <tt>end</tt>, given with the double precision
     */
Calculates the distance between origin and end.
@param origin start point
@param end end point
@return Geographicaldistance between origin and end, given with the double precision
Calculates the distance between origin and end . @param origin start point @param end end point @return Geographicaldistance between origin and end given with the double precision
public static double distance(Point2D.Double origin, Point2D.Double end){
	double drlon;
	double drlat;
	double rlat1;
	double rlon1;
	double rlat2;
	double rlon2;
	BigDecimal drlonBD;
	BigDecimal drlatBD;
	BigDecimal drlonBD_half;
	BigDecimal drlatBD_half;
	BigDecimal rlat1BD;
	BigDecimal rlon1BD;
	BigDecimal rlat2BD;
	BigDecimal rlon2BD;
	BigDecimal bd_of_2 = new BigDecimal(2);
	BigDecimal bd_of_2PI = bd_of_2.multiply(new BigDecimal(Math.PI));
	BigDecimal rBD;
	BigDecimal aBD;
	double a;
	double c;
	double d;
	rlat1=Math.toRadians(origin.getX()); 
	rlat2=Math.toRadians(end.getX());
	rlon1=Math.toRadians(origin.getY());
	rlon2=Math.toRadians(end.getY());
	rlat1BD= new BigDecimal(rlat1);
	rlat2BD= new BigDecimal(rlat2);
	rlon1BD= new BigDecimal(rlon1);
	rlon2BD= new BigDecimal(rlon2);
	/* calculate r - the earth's radius at this latitude
	 * r = (GEO_A * Math.sqrt(1 - GEO_E2)) / (1 - (GEO_E2 * Math.pow(Math.sin(Math.toRadians(this.lat)),2)));
	 * solved first part of this (see class static vars), to save clocks
	 */
	rBD = new BigDecimal(Ra / (1 - (GEO_E2 * Math.pow(Math.sin(rlat1),2))));
	drlatBD=((rlat2BD.subtract(rlat1BD)).abs()).min(bd_of_2PI.subtract(rlat2BD.subtract(rlat1BD).abs()));
	drlonBD=((rlon2BD.subtract(rlon1BD)).abs()).min(bd_of_2PI.subtract(rlon2BD.subtract(rlon1BD).abs()));
	drlatBD_half=drlatBD.divide(bd_of_2,20,BigDecimal.ROUND_HALF_EVEN);
	drlonBD_half=drlonBD.divide(bd_of_2,20,BigDecimal.ROUND_HALF_EVEN);
	aBD = (new BigDecimal(Math.sin(drlatBD_half.doubleValue()))).multiply(new BigDecimal(Math.sin(drlatBD_half.doubleValue()))).add((new BigDecimal(Math.cos(rlat1))).multiply(new BigDecimal(Math.cos(rlat2))).multiply(new BigDecimal(Math.sin(drlonBD_half.doubleValue()))).multiply(new BigDecimal(Math.sin(drlonBD_half.doubleValue())))); 
	a = aBD.doubleValue();
	c = 2 * Math.asin(Math.min(1,Math.sqrt(a))); 
	d = rBD.doubleValue() * c;
	return d;
    }
public static double distance ( Point2D . Double origin , Point2D . Double end ) { double drlon ; double drlat ; double rlat1 ; double rlon1 ; double rlat2 ; double rlon2 ; BigDecimal drlonBD ; BigDecimal drlatBD ; BigDecimal drlonBD_half ; BigDecimal drlatBD_half ; BigDecimal rlat1BD ; BigDecimal rlon1BD ; BigDecimal rlat2BD ; BigDecimal rlon2BD ; BigDecimal bd_of_2 = new BigDecimal ( 2 ) ; BigDecimal bd_of_2PI = bd_of_2 . multiply ( new BigDecimal ( Math . PI ) ) ; BigDecimal rBD ; BigDecimal aBD ; double a ; double c ; double d ; rlat1 = Math . toRadians ( origin . getX ( ) ) ; rlat2 = Math . toRadians ( end . getX ( ) ) ; rlon1 = Math . toRadians ( origin . getY ( ) ) ; rlon2 = Math . toRadians ( end . getY ( ) ) ; rlat1BD = new BigDecimal ( rlat1 ) ; rlat2BD = new BigDecimal ( rlat2 ) ; rlon1BD = new BigDecimal ( rlon1 ) ; rlon2BD = new BigDecimal ( rlon2 ) ; /* calculate r - the earth's radius at this latitude
	 * r = (GEO_A * Math.sqrt(1 - GEO_E2)) / (1 - (GEO_E2 * Math.pow(Math.sin(Math.toRadians(this.lat)),2)));
	 * solved first part of this (see class static vars), to save clocks
	 */ rBD = new BigDecimal ( Ra / ( 1 - ( GEO_E2 * Math . pow ( Math . sin ( rlat1 ) , 2 ) ) ) ) ; drlatBD = ( ( rlat2BD . subtract ( rlat1BD ) ) . abs ( ) ) . min ( bd_of_2PI . subtract ( rlat2BD . subtract ( rlat1BD ) . abs ( ) ) ) ; drlonBD = ( ( rlon2BD . subtract ( rlon1BD ) ) . abs ( ) ) . min ( bd_of_2PI . subtract ( rlon2BD . subtract ( rlon1BD ) . abs ( ) ) ) ; drlatBD_half = drlatBD . divide ( bd_of_2 , 20 , BigDecimal . ROUND_HALF_EVEN ) ; drlonBD_half = drlonBD . divide ( bd_of_2 , 20 , BigDecimal . ROUND_HALF_EVEN ) ; aBD = ( new BigDecimal ( Math . sin ( drlatBD_half . doubleValue ( ) ) ) ) . multiply ( new BigDecimal ( Math . sin ( drlatBD_half . doubleValue ( ) ) ) ) . add ( ( new BigDecimal ( Math . cos ( rlat1 ) ) ) . multiply ( new BigDecimal ( Math . cos ( rlat2 ) ) ) . multiply ( new BigDecimal ( Math . sin ( drlonBD_half . doubleValue ( ) ) ) ) . multiply ( new BigDecimal ( Math . sin ( drlonBD_half . doubleValue ( ) ) ) ) ) ; a = aBD . doubleValue ( ) ; c = 2 * Math . asin ( Math . min ( 1 , Math . sqrt ( a ) ) ) ; d = rBD . doubleValue ( ) * c ; return d ; }
Calculates the distance between <tt>origin</tt> and <tt>end</tt>.
Calculates the distance between <tt > origin< / tt > and <tt > end< / tt > .
// measures come in as degrees, the trig functions want radians
 //////System.out.println("rlat1 rlon1 rlat2 rlon2: "+rlat1+" "+rlon1+" "+rlat2+" "+rlon2);
 //////System.out.println("drlat, drlon : "+drlat+" "+drlon);
 //a = Math.pow(Math.sin(drlat/2),2) + Math.cos(rlat1) * Math.cos(rlat2) * Math.pow(Math.sin(drlon/2),2); 
 //go back to a, since BigDecimal does not support square roots...
