Advertisement
cd62131

Theta

Jul 19th, 2014
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.90 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use feature 'say';
  5. use Math::Trig;
  6. sub theta {
  7.   my ($x1, $y1, $x2, $y2) = @_;
  8.   $x1 = deg2rad $x1;
  9.   $y1 = deg2rad $y1;
  10.   $x2 = deg2rad $x2;
  11.   $y2 = deg2rad $y2;
  12.   my $theta = rad2deg(
  13.     acos(1 - (1 / 2) *
  14.       (
  15.         (cos($y1) * sin($x1) - cos($y2) * sin($x2)) ^ 2 +
  16.         (cos($y1) * cos($x1) - cos($y2) * cos($x2)) ^ 2 +
  17.         (sin($y1) - sin($y2)) ^ 2
  18.       )
  19.     )
  20.   );
  21.   return $theta;
  22. }
  23. my $data = [];
  24. my $result = [];
  25. while (<>) {
  26.   chomp;
  27.   my @d = split;
  28.   push @$data, \@d;
  29. }
  30. my $size = scalar @$data;
  31. for (my $i = 0; $i < $size; $i++) {
  32.   for (my $j = $i + 1; $j < $size; $j++) {
  33.     my $r = [$data->[$i][0], $data->[$i][1], $data->[$j][0], $data->[$j][1]];
  34.     push @$r, theta @$r;
  35.     push @$result, $r;
  36.   }
  37. }
  38. @$result = sort { $a->[4] <=> $b->[4] } @$result;
  39. foreach my $r (@$result) {
  40.   say join "\t", @$r;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement