PHP rad2deg
In PHP, rad2deg converts an angle from radians to degrees by multiplying by 180/π. Half a turn is π radians, or 180 degrees.
A simple example
rad2deg
- Start with π radians
- Do this Convert a half-turn to degrees
- Result 180°
Syntax
rad2deg($radians)
Run these examples in PHP
Save one example at a time as lesson.php. Use PHP 8.2 or later.
php lesson.phpLabel a quarter turn in degrees
A navigation wheel makes one quarter turn. Convert the angle from radians to degrees before giving it to the display component that labels the wheel.
<?php
$radians = 1.5707963267948966;
printf("%.3F\n", rad2deg($radians));
90.000
One quarter turn is approximately 1.571 radians and displays as 90 degrees.
Label a turn on a navigation dial
A dial calculation produces an angle in radians, while the person using the dial reads degrees. Convert a familiar turn to confirm the scale on the display.
<?php
$angle = 3.141592653589793;
printf("%.3F\n", rad2deg($angle));
180.000
A half turn is pi radians, which the dial displays as 180 degrees.
Label a dial rotation
A drawing tool rotates a pointer by one radian. A student wants to annotate the same turn in degrees.
Using 1 gives 57.3 ° for this measurement.
What to watch for
Converting the unit does not wrap an angle into a single revolution.