Coder Social home page Coder Social logo

p5-geo-ellipsoid's People

Contributors

jimsgibson avatar pjacklam avatar

Watchers

 avatar  avatar  avatar

Forkers

mauke

p5-geo-ellipsoid's Issues

Reverse bearing from internal _forward function

Hi,

The internal Fortran derived code has reverse bearing available, but it is commented out and not returned by the internal _forward and public "at" function. The reverse bearing is same as bearing available from "to" function for distances less than about 20 000 km (antipode), but becomes impossible to calculate for longer distances without return of the $baz variable from the _forward function.

Here is proposed patch, which adds "atb" function and reroutes existing "at" function to internally call "atb". "at" functionality is preserved and new "atb" can be called directly to get correct reverse bearing beyond antipode distance. I hope I did not break anything.

Regards,
Sami

Ellipsoid.pm.patch.txt

--- Ellipsoid.pm.orig	Tue Jan 19 15:33:31 2021
+++ Ellipsoid.pm	Thu Jan 28 00:14:49 2021
@@ -775,15 +775,36 @@
 sub at
 {
   my $self = shift;
+  my( $lat, $lon, $r, $az ) = @_;
+  print "at($lat,$lon,$r,$az)\n" if $DEBUG;
+  my( $lat2, $lon2, $baz ) = $self->atb($lat,$lon,$r,$az);
+  print "atb returns ($lat2,$lon2,$baz)\n" if $DEBUG;
+  return ( $lat2, $lon2 );
+}
+
+=pod
+
+=item atb
+
+Returns the list (latitude,longitude,reverse_bearing) in degrees or radians that is a
+specified range and bearing from a given location.
+
+    my( $lat2, $lon2, $baz ) = $geo->atb( $lat1, $lon1, $range, $bearing );
+
+=cut
+
+sub atb
+{
+  my $self = shift;
   my $units = $self->{angle_unit};
   my( $lat, $lon, $az ) = _normalize_input($units,@_[0,1,3]);
   my $r = $_[2];
-  print "at($lat,$lon,$r,$az)\n" if $DEBUG;
-  my( $lat2, $lon2 ) = $self->_forward($lat,$lon,$r,$az);
-  print "_forward returns ($lat2,$lon2)\n" if $DEBUG;
+  print "atb($lat,$lon,$r,$az)\n" if $DEBUG;
+  my( $lat2, $lon2, $baz ) = $self->_forward($lat,$lon,$r,$az);
+  print "_forward returns ($lat2,$lon2,$baz)\n" if $DEBUG;
   $self->_normalize_output('longitude_symmetric',$lon2);
   $self->_normalize_output('latitude_symmetric',$lat2);
-  return ( $lat2, $lon2 );
+  return ( $lat2, $lon2, $baz );
 }
 
 =pod
@@ -1052,10 +1073,10 @@
   $c = (((((-3.0*$c2a)+4.0)*$f)+4.0)*$c2a*$f)/16.0;
   $d = (((($e*$cy*$c) + $cz)*$sy*$c)+$y)*$sa;
   my $lon2 = $lon1 + $x - (1.0-$c)*$d*$f;
-  #$baz = atan2($sa,$baz) + pi;
+  $baz = atan2($sa,$baz) + pi;
 
   # return result
-  return ($lat2,$lon2);
+  return ($lat2,$lon2,$baz);
 
 }
 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.