Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature 'say';
- use Math::Trig;
- sub theta {
- my ($x1, $y1, $x2, $y2) = @_;
- $x1 = deg2rad $x1;
- $y1 = deg2rad $y1;
- $x2 = deg2rad $x2;
- $y2 = deg2rad $y2;
- my $theta = rad2deg(
- acos(1 - (1 / 2) *
- (
- (cos($y1) * sin($x1) - cos($y2) * sin($x2)) ^ 2 +
- (cos($y1) * cos($x1) - cos($y2) * cos($x2)) ^ 2 +
- (sin($y1) - sin($y2)) ^ 2
- )
- )
- );
- return $theta;
- }
- my $data = [];
- my $result = [];
- while (<>) {
- chomp;
- my @d = split;
- push @$data, \@d;
- }
- my $size = scalar @$data;
- for (my $i = 0; $i < $size; $i++) {
- for (my $j = $i + 1; $j < $size; $j++) {
- my $r = [$data->[$i][0], $data->[$i][1], $data->[$j][0], $data->[$j][1]];
- push @$r, theta @$r;
- push @$result, $r;
- }
- }
- @$result = sort { $a->[4] <=> $b->[4] } @$result;
- foreach my $r (@$result) {
- say join "\t", @$r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement