Aug 29

Trigonometry cheat sheet

Category: Linux,Perl,WIP   — Published by goeszen on August 29, 2015 at 8:22 pm

This is a rather amateurish Perl cheat sheet for when you're starting with trigonometry in Perl.

First, Perl uses radians instead of degrees, so you'll have to use Math::Trig's rad2deg and deg2rad functions to computer the one or the other, compare Perl Cookbook, ~ chapter 2.

Then you might want to calculate the arcsin of something:

my $deg_alpha = rad2deg(asin($distance_BC * sin(90) / $distance_AB));

asin() from Math::Trig is the function of choice here, but it's not equal to a (non existing) arcsin(), it returns
radians, so you have to send resulting values through rad2deg to get what a dedicated arcsin would have returned.

Another note on tangens: In Math::Trig is a tan() function, but in case you want to code it up by hand, here it is:

sub tan {
my $angle = shift;
return( sin($angle) / cos($angle) );

Leave a Reply