libvec.pl
changeset 2 75410953a4d5
parent 0 a5233793bf69
child 3 55a8c407d38e
equal deleted inserted replaced
1:d17eb00c168b 2:75410953a4d5
     1 #======================================================================
     1 #======================================================================
     2 #                    L I B V E C . P L 
     2 #                    . . / L I B / L I B V E C . P L 
     3 #                    doc: Sat Mar 20 12:50:32 1999
     3 #                    doc: Sat Mar 20 12:50:32 1999
     4 #                    dlm: Thu Apr 22 11:32:54 2010
     4 #                    dlm: Tue Jun  5 08:38:52 2012
     5 #                    (c) 1999 A.M. Thurnherr
     5 #                    (c) 1999 A.M. Thurnherr
     6 #                    uE-Info: 147 34 NIL 0 0 72 2 2 4 NIL ofnI
     6 #                    uE-Info: 318 0 NIL 0 0 70 2 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8 
     8 
     9 # HISTORY:
     9 # HISTORY:
    10 #	Mar 20, 1999: - created for ANTS_2.1 (no more c-code)
    10 #	Mar 20, 1999: - created for ANTS_2.1 (no more c-code)
    11 #	May 27, 1999: - added polar/cartesian conversions
    11 #	May 27, 1999: - added polar/cartesian conversions
    29 #				  - same routines now return nan on nan input
    29 #				  - same routines now return nan on nan input
    30 #	Jan 15, 2007: - BUG: vel_dir() was broken
    30 #	Jan 15, 2007: - BUG: vel_dir() was broken
    31 #	Jun 14, 2009: - added p_vel()
    31 #	Jun 14, 2009: - added p_vel()
    32 #	Nov  5, 2009: - added angle(); vel_bias() => angle_diff()
    32 #	Nov  5, 2009: - added angle(); vel_bias() => angle_diff()
    33 #	Apr 22, 2010: - added angle_ts()
    33 #	Apr 22, 2010: - added angle_ts()
       
    34 #	Jun  5, 2012: - added &closestPointOnStraightLine()
    34 
    35 
    35 require "$ANTS/libPOSIX.pl";	# acos()
    36 require "$ANTS/libPOSIX.pl";	# acos()
    36 
    37 
    37 #----------------------------------------------------------------------
    38 #----------------------------------------------------------------------
    38 # &rad()							calc radians
    39 # &rad()							calc radians
   295 
   296 
   296 	return (&dist($S,$W,$S,$E) + &dist($N,$W,$N,$E)) / 2 *
   297 	return (&dist($S,$W,$S,$E) + &dist($N,$W,$N,$E)) / 2 *
   297 		   (&dist($S,$W,$N,$W) + &dist($S,$E,$N,$E)) / 2;
   298 		   (&dist($S,$W,$N,$W) + &dist($S,$E,$N,$E)) / 2;
   298 }
   299 }
   299 
   300 
       
   301 #----------------------------------------------------------------------
       
   302 # &closestPointOnStraightLine(lat,lon,lat1,lonA,lat2,lon2)
       
   303 #	- determine point on line segment from <lat1,lonA> to <lat2,lon2> that
       
   304 #	  is closest to target point <lat,lon>
       
   305 #   - http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line
       
   306 #	- NOT DONE IN PLANAR GEOMETRY => USE ONLY IN SMALL DOMAINS
       
   307 #----------------------------------------------------------------------
       
   308 
       
   309 sub closestPointOnStraightLine(@)
       
   310 {
       
   311 	my($latP,$lonP,$latA,$lonA,$latB,$lonB) =
       
   312 		&antsFunUsage(6,'ffffff','pnt_lat, pnt_lon, lne_latA, lne_lonA, lne_latB, lne_lonB',@_);
       
   313 
       
   314 	my($ABlon) = $lonB - $lonA; my($ABlat) = $latB - $latA; 
       
   315 	my($APlon) = $lonP - $lonA; my($APlat) = $latP - $latA;
       
   316 	my($t) = ($APlon*$ABlon + $APlat*$ABlat) / ($ABlon**2 + $ABlat**2);
       
   317 	return (undef,undef) unless ($t>=0 && $t<=1);
       
   318 	return ($latA + $t*$ABlat,$lonA + $t*$ABlon);
       
   319 }
       
   320 
   300 1;
   321 1;