#!/usr/bin/perl
# Make a KML circle' coordinates
# Copyright       : http://www.fsf.org/copyleft/gpl.html
# Author          : Dan Jacobson -- http://jidanni.org/
# Created On      : Sat Mar 16 09:01:16 2013
# Last Modified On: Wed Apr 10 15:13:42 2013
# Update Count    : 48
# Usage: $0 longitude_of_center latitude_of_center radius_in_nautical_miles start-vertex end-vertex degrees-per-vertex
# E.g., $0 22.5 -33.3 388 180 360 15
# Output: lon,lat lon,lat lon,lat
use strict;
use warnings FATAL => 'all';
use Math::Trig;
use Math::Trig 'great_circle_destination';

# RCR7 Lower
my @c=(circle( 119.3425, 23.305, 4000 * 0.3048, 6.5, 180, 360, 20 ),
       reverse circle( 119.3425, 23.305, 4000 * 0.3048, 2.6, 180, 360, 20 ));
print join "\n",@c,$c[0],"------",

  # RCR7 Upper
  circle( 119.3425, 23.305, 15000 * 0.3048, 2.6, 0, 360, 20 );

sub circle {
    my @answer;
    for ( my $diro = $_[4] ; $diro <= $_[5] ; $diro += $_[6] ) {
        my ( $thetad, $phid, undef ) = great_circle_destination(
            deg2rad( $_[0] ),
            deg2rad( 90 - $_[1] ),
            deg2rad($diro),
            deg2rad( $_[3] / 60 )
        );
        push @answer, sprintf "%f,%f,%s", rad2deg($thetad), rad2deg($phid),
          $_[2];
    }
    return @answer;
}
