Movatterモバイル変換


[0]ホーム

URL:


How to convert degrees to radians in JavaScript

calendarSunday, September 28, 2025

Converting degrees to radians is crucial for trigonometric functions, mathematical calculations, animation rotations, and implementing features like canvas graphics or geometric transformations in JavaScript applications.With over 25 years of experience in software development and as the creator of CoreUI, I’ve implemented degree-to-radian conversion in components like chart rotations, animation systems, and mathematical utilities where JavaScript’s trigonometric functions require radian input for accurate calculations.From my extensive expertise, the standard mathematical approach is multiplying degrees by π/180, using JavaScript’sMath.PI constant for precision.This conversion is essential since JavaScript’s trigonometric functions (sin, cos, tan) expect radian values rather than degrees.

Multiply degrees by π/180 to convert to radians.

constdegrees=90constradians=degrees*(Math.PI/180)// Result: 1.5707963267948966 (π/2)constdegreesToRadians=(deg)=>deg*(Math.PI/180)// Usage: degreesToRadians(180) returns π (3.141592653589793)

The conversion formuladegrees * (Math.PI / 180) is based on the mathematical relationship that 180 degrees equals π radians. In this example, 90 degrees converts to π/2 radians (approximately 1.57), which is the correct input forMath.sin(radians) to return 1. The function version provides a reusable converter for any degree value. Common conversions: 90° = π/2 radians, 180° = π radians, 360° = 2π radians. This conversion is necessary because JavaScript’sMath.sin(),Math.cos(), andMath.tan() functions require radian inputs.

Best Practice Note:

This is the same approach we use in CoreUI components for trigonometric calculations, animation rotations, and geometric transformations across our component library.Create a utility function for reusability:const toRadians = deg => deg * Math.PI / 180. Always convert degrees to radians before using trigonometric functions. The inverse conversion usesradians * (180 / Math.PI). This conversion is fundamental for any application involving angles, rotations, or trigonometric calculations in JavaScript.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Łukasz Holeczek, Founder of CoreUI, is a seasoned Fullstack Developer and entrepreneur with over 25 years of experience. As the lead developer for all JavaScript, React.js, and Vue.js products at CoreUI, they specialize in creating open-source solutions that empower developers to build better and more accessible user interfaces.

With expertise in TypeScript, JavaScript, Node.js, and modern frameworks like React.js, Vue.js, and Next.js, Łukasz combines technical mastery with a passion for UI/UX design and accessibility. CoreUI’s mission is to provide developers with tools that enhance productivity while adhering to accessibility standards.

Łukasz shares its extensive knowledge through a blog with technical software development articles. It also advises enterprise companies on building solutions from A to Z. Through CoreUI, it offers professional services, technical support, and open-core products that help developers and businesses achieve their goals.

Learn more about CoreUI’s solutions and see how your business can benefit from working with us.
Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to fix “SyntaxError: Cannot use import statement outside a module”?
How to fix “SyntaxError: Cannot use import statement outside a module”?
calendarSunday, January 7, 2024

What is CoreUI and Why Should You Use It for Your Next Admin Dashboard?
What is CoreUI and Why Should You Use It for Your Next Admin Dashboard?
calendarThursday, July 10, 2025

How to force a React component to re-render
How to force a React component to re-render
calendarMonday, September 9, 2024

Maintaining Accessibility with React createPortal and aria-owns: A Complete Guide
Maintaining Accessibility with React createPortal and aria-owns: A Complete Guide
calendarMonday, August 4, 2025

Answers by CoreUI Core Team

How to format date as YYYY-MM-DD in JavaScript
How to check if a string contains a substring in JavaScript
How to validate props in Vue
How to find the minimum value in an array in JavaScript
How to use CSS modules in Vue
How to use inline styles in Vue

[8]ページ先頭

©2009-2025 Movatter.jp