1 #====================================================================== |
1 #====================================================================== |
2 # . . / L I B / L I B V E C . P L |
2 # . . / A N T S 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: Tue Jun 5 08:38:52 2012 |
4 # dlm: Mon Jun 11 11:12:06 2012 |
5 # (c) 1999 A.M. Thurnherr |
5 # (c) 1999 A.M. Thurnherr |
6 # uE-Info: 318 0 NIL 0 0 70 2 2 4 NIL ofnI |
6 # uE-Info: 35 69 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 |
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 # Jun 5, 2012: - added &closestPointOnStraightLine() |
|
35 # Jun 11, 2012: - addeed $t output to &closestPointOnStraightLine() |
35 |
36 |
36 require "$ANTS/libPOSIX.pl"; # acos() |
37 require "$ANTS/libPOSIX.pl"; # acos() |
37 |
38 |
38 #---------------------------------------------------------------------- |
39 #---------------------------------------------------------------------- |
39 # &rad() calc radians |
40 # &rad() calc radians |
297 return (&dist($S,$W,$S,$E) + &dist($N,$W,$N,$E)) / 2 * |
298 return (&dist($S,$W,$S,$E) + &dist($N,$W,$N,$E)) / 2 * |
298 (&dist($S,$W,$N,$W) + &dist($S,$E,$N,$E)) / 2; |
299 (&dist($S,$W,$N,$W) + &dist($S,$E,$N,$E)) / 2; |
299 } |
300 } |
300 |
301 |
301 #---------------------------------------------------------------------- |
302 #---------------------------------------------------------------------- |
302 # &closestPointOnStraightLine(lat,lon,lat1,lonA,lat2,lon2) |
303 # ($lat,$lon,$t) = &closestPointOnStraightLine(lat,lon,lat1,lonA,lat2,lon2) |
303 # - determine point on line segment from <lat1,lonA> to <lat2,lon2> that |
304 # - determine point on line segment from <lat1,lonA> to <lat2,lon2> that |
304 # is closest to target point <lat,lon> |
305 # is closest to target point <lat,lon> |
|
306 # - $t [0-1] output indicates where along the line segment the closest |
|
307 # point lies |
305 # - http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line |
308 # - http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line |
306 # - NOT DONE IN PLANAR GEOMETRY => USE ONLY IN SMALL DOMAINS |
309 # - NOT DONE IN PLANAR GEOMETRY => USE ONLY IN SMALL DOMAINS |
307 #---------------------------------------------------------------------- |
310 #---------------------------------------------------------------------- |
308 |
311 |
309 sub closestPointOnStraightLine(@) |
312 sub closestPointOnStraightLine(@) |
313 |
316 |
314 my($ABlon) = $lonB - $lonA; my($ABlat) = $latB - $latA; |
317 my($ABlon) = $lonB - $lonA; my($ABlat) = $latB - $latA; |
315 my($APlon) = $lonP - $lonA; my($APlat) = $latP - $latA; |
318 my($APlon) = $lonP - $lonA; my($APlat) = $latP - $latA; |
316 my($t) = ($APlon*$ABlon + $APlat*$ABlat) / ($ABlon**2 + $ABlat**2); |
319 my($t) = ($APlon*$ABlon + $APlat*$ABlat) / ($ABlon**2 + $ABlat**2); |
317 return (undef,undef) unless ($t>=0 && $t<=1); |
320 return (undef,undef) unless ($t>=0 && $t<=1); |
318 return ($latA + $t*$ABlat,$lonA + $t*$ABlon); |
321 return ($latA + $t*$ABlat,$lonA + $t*$ABlon, $t); |
319 } |
322 } |
320 |
323 |
321 1; |
324 1; |