The MathUtils.degToRad()
function is a utility function provided by the Three.js library to convert values from degrees to radians.
MathUtils.degToRad(degrees)
degrees
- input angle in degreesThe function returns the input angle converted to radians.
Convert 45 degrees to radians.
const angleInDeg = 45;
const angleInRad = MathUtils.degToRad(angleInDeg);
console.log(angleInRad); // Output: 0.7853981633974483
Find the sine of an angle in degrees.
const angleInDeg = 30;
const angleInRad = MathUtils.degToRad(angleInDeg);
const sinValue = Math.sin(angleInRad);
console.log(sinValue); // Output: 0.5
The MathUtils.degToRad()
function is mainly used in graphics programming for converting angles between different systems of measurement. Since the Three.js library mainly deals with 3D graphics and animations, this function becomes essential for developers.