-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathrectangle_sides_from_diagonal_angles.pl
More file actions
executable file
·39 lines (29 loc) · 1.1 KB
/
rectangle_sides_from_diagonal_angles.pl
File metadata and controls
executable file
·39 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# Date: 22 January 2018
# https://github.com/trizen
# Formula for finding the smallest integer sides of a rectangle, given the internal angles of its diagonal.
use 5.020;
use strict;
use warnings;
use experimental qw(signatures);
use Math::AnyNum qw(:trig :overload);
sub diagonal_angles ($x, $y, $z) {
(
acos(($x**2 + $z**2 - $y**2) / (2 * $x * $z)),
acos(($y**2 + $z**2 - $x**2) / (2 * $y * $z)),
);
}
sub rectangle_side_from_angle ($theta) {
sqrt((cos($theta)**2)->rat_approx->numerator);
}
my $x = 43; # side 1
my $y = 97; # side 2
my $z = sqrt($x**2 + $y**2); # diagonal
my ($a1, $a2) = diagonal_angles($x, $y, $z);
say "The internal diagonal angles:";
say ' ', rad2deg($a1); #=> 66.0923395058274991877532084833790002675999587054
say ' ', rad2deg($a2); #=> 23.9076604941725008122467915166209997324000412946
say "\nThe smallest side lengths matching the internal angles:";
say rectangle_side_from_angle($a1); #=> 43
say rectangle_side_from_angle($a2); #=> 97