- Perl ›
- Numerical value ›
- here
Convert angle to radians
To convert an angle expressed in degrees (30 °, 90 °, etc.) to radians (π/6, π/4, etc.) Use the deg2rad function of the Math::Trig module. To do the opposite, use the rad2deg function.
use Math::Trig 'pi', 'deg2rad'; # Convert the degree angle to the radian angle my $rad = deg2rad(30); # Convert radian angle to degree angle my $deg = rad2deg (pi/6);
Trigonometric functions are explained in detail on the following pages.
Degree method and radian method
The degree method is a method of expressing an angle that uses a circle divided into 360 as a unit. Expressions of angles that you often see 30 °, 90 °, etc. are angles expressed in degrees.
On the other hand, the radian method is a method of expressing an angle in units of the central angle of a sector whose radius is r and whose circumference is r. 180 ° in degrees is π in radians. Keeping this in mind, 30 ° is one sixth of 180 °, so we can find that it is equal to π/6.
# !/usr/bin/perl use strict; use warnings; use Math::Trig qw/pi deg2rad rad2deg/; print "(1) Convert angles to radians.\n"; print deg2rad(30) . "\n"; print "(2) Convert radians to angles.\n"; print rad2deg (pi/6) . "\n";