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;
- my $cos = {};
- my $sin = {};
- sub theta {
- my ($x1, $y1, $x2, $y2) = map { deg2rad int $_ } @_;
- $cos->{$x1} or $cos->{$x1} = cos $x1;
- $sin->{$x1} or $sin->{$x1} = sin $x1;
- $cos->{$y1} or $cos->{$y1} = cos $y1;
- $sin->{$y1} or $sin->{$y1} = sin $y1;
- $cos->{$x2} or $cos->{$x2} = cos $x2;
- $sin->{$x2} or $sin->{$x2} = sin $x2;
- $cos->{$y2} or $cos->{$y2} = cos $y2;
- $sin->{$y2} or $sin->{$y2} = sin $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 = [];
- while (<>) {
- chomp;
- next if /\A\s*\z/;
- my @d = split;
- next if 2 != (scalar @d);
- 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;
- say join "\t", @$r;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement