How can I convert from degrees to radians?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Converting degrees to radians is one of the most common angle conversions in math, graphics, and programming. The rule is simple: multiply the degree value by pi / 180.
That formula comes from the fact that a full circle is 360 degrees and also 2 * pi radians. Once you know that relationship, the conversion becomes mechanical and easy to code.
Start with the Core Formula
The conversion formula is:
radians = degrees * (pi / 180)
So:
- '
180degrees becomespiradians' - '
90degrees becomespi / 2' - '
45degrees becomespi / 4'
For example, converting 60 degrees:
60 * (pi / 180) = pi / 3
That is the exact symbolic answer. In code, you usually compute a floating-point approximation.
Convert in Code
In Python:
The second line uses Python's built-in helper, which is usually the clearest option when one exists.
In JavaScript:
In Swift:
These examples all use the same formula. Only the language syntax changes.
Know Why Radians Matter
Radians are not just another unit. They are the natural angle unit in many mathematical formulas. Calculus, trigonometric derivatives, and many graphics or physics APIs assume radians.
That is why code often converts to radians even when the input is easier for humans to think about in degrees.
For example:
- game engines often use radians for rotation functions
- trigonometric libraries expect radians
- physics formulas for angular velocity are usually expressed in radians
So the conversion is often a boundary between user-facing input and computation-facing math.
It is also a good mental check when reading formulas. If a trigonometric identity or API documentation assumes radians, converting once at the input boundary is usually cleaner than sprinkling degree-to-radian conversions throughout the code.
Convert Back When Needed
The reverse formula is just as useful:
degrees = radians * (180 / pi)
In Python:
Knowing both directions helps when debugging code that mixes UI input, mathematical functions, and stored values.
Common Pitfalls
The biggest mistake is mixing up the fraction and multiplying by 180 / pi when you meant degrees-to-radians. That applies the reverse conversion and produces the wrong scale.
Another common issue is forgetting that most programming language trig functions expect radians. Passing degree values directly into sin, cos, or tan usually produces confusing results.
It is also easy to lose track of whether a value is symbolic or numeric. pi / 3 is exact as math notation, while the code version is a floating-point approximation.
Finally, keep the unit explicit in variable names or comments when the codebase mixes both degrees and radians. That prevents subtle bugs in geometry and graphics code.
Unit clarity saves debugging time.
Summary
- Convert degrees to radians with
degrees * (pi / 180). - Convert radians to degrees with
radians * (180 / pi). - Use built-in helpers such as
math.radians()when available. - Remember that many math and graphics APIs expect radians.
- Keep angle units explicit so degree and radian values are not mixed accidentally.
Related reading
- How can I convert from degrees to radians?
- How can I count how many horizontal brush strokes are required to draw an array of buildings?
- How can I create the cartesian product of a vector of vectors?
- How can I determine all possible ways a subsequence can be removed from a sequence?
- How can I find hole in a 2D matrix?
- How can I find the minimal circle include some given points?
- How can I find the number of Hamiltonian cycles in a complete undirected graph?
- How can I fit a Bézier curve to a set of data?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.