All pastes #470622 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-04 12:02 UTC
rendered paste body
#!/usr/bin/perl

use strict;
use Math::Trig;

  my $lat1deg = -36.788889;
  my $lon1deg = 174.681821;
  my $lat2deg = -36.785127;
  my $lon2deg = 174.668494;

  my $lat1 = deg2rad($lat1deg);
  my $lat2 = deg2rad($lat2deg);
  my $lon1 = $lon1deg;
  my $lon2 = $lon2deg;

  my $dlon = $lon2 - $lon1;
  if ($dlon > 180) {
    $dlon = $dlon - 360;
  }
  if ($dlon< -180) {
    $dlon = 360 + $dlon;
  }

  my $rdlon = deg2rad($dlon);
  my $cosdist = (sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($rdlon));
  my $rdist = acos($cosdist);

  my $nautical_miles = abs(rad2deg($rdist) * 60.);
  my $statue_miles = abs((rad2deg($rdist) * 60.) * 1.15077945);
  my $statue_km = abs((rad2deg($rdist) * 60.) * 1.8520000031807997);

  print "Blah: $lat1, $lat2, $lat1, $lat2, $dlon, $cosdist\n";

  print "Miles: $nautical_miles\n";