math.deg() function takes an angle in radians as input and returns the equivalent angle in degrees. This function is helpful when working with angles in a more human-readable and familiar unit, especially for tasks like user interfaces or displaying angles in degrees rather than radians.
Note: It’s important to be cautious of rounding errors when converting between degrees and radians due to computer’s floating-point representation, especially for small or large angles. Rounding errors occur when converting between degrees and radians due to the inherent limitations of number representations.
math.deg() function must be called with an argument using the following syntax:
xis a number representing an angle in radians to be convert to degrees. If no argument is passed, the program will raise an error.
The following example shows the basic use of
local angleInRadians = math.pi / 4local angleInDegrees = math.deg(angleInRadians)print("The angle in degrees equals: " .. angleInDegrees)
The above example results in the following output:
The angle in degrees equals: 45.0