Skip to content

← Back to Overview

Degrees to Radians Conversion

Concept Explanation

What is it?

This program converts an angle measured in degrees to its equivalent in radians. Degrees and radians are two common units for measuring angles. - A degree is 1/360th of a full rotation. - A radian is the angle subtended at the center of a circle by an arc that is equal in length to the radius of the circle. One full rotation is radians.

Why is it important?

Radians are the standard unit of angular measure in many areas of mathematics (especially calculus), physics, and engineering. They simplify many formulas and make calculations more natural in mathematical contexts. Understanding this conversion is crucial for working with trigonometric functions and geometric calculations in various programming applications.

Where is it used?

  • Physics and Engineering: Calculations involving rotational motion, wave mechanics, and oscillations.
  • Computer Graphics: Defining rotations and transformations of objects in 2D and 3D environments.
  • Mathematics: Trigonometric functions in programming languages usually expect arguments in radians.
  • Robotics: Calculating joint angles for robot arms.

Real-world example

When programming a game or a simulation where objects rotate, you often define angles in degrees for user convenience but convert them to radians internally before passing them to mathematical functions (like sin(), cos()) provided by programming libraries. If a user wants to rotate an object by 90 degrees, the program converts 90 degrees to π/2 radians before applying the rotation.


Algorithm

  1. Start.
  2. Get the angle in degrees (degrees) from the user.
  3. Use the value of PI (approximately 3.14159...).
  4. Apply the conversion formula: radians = degrees * PI / 180.
  5. Display the original angle in degrees and the calculated angle in radians.
  6. End.

Conversion Formula: radians = degrees × PI / 180

Edge Cases: - Non-numeric input for degrees (handled by language-specific error mechanisms or explicit validation). - Large or negative angle values: The conversion formula holds true for all real numbers.


Implementations

import java.util.Scanner;

public class DegreesToRadians {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter angle in degrees: ");
        double degrees = scanner.nextDouble();

        // Convert degrees to radians
        double radians = degrees * Math.PI / 180;

        System.out.println("Degrees: " + degrees + "°");
        System.out.println("Radians: " + String.format("%.4f", radians) + " rad"); // Format to 4 decimal places

        scanner.close();
    }
}
import math

# Get degrees from user
degrees_str = input("Enter angle in degrees: ")
degrees = float(degrees_str)

# Convert degrees to radians
radians = degrees * math.pi / 180

print(f"Degrees: {degrees}°")
print(f"Radians: {radians:.4f} rad") # Format to 4 decimal places
#include <stdio.h>
#include <math.h> // Required for M_PI or define PI

int main() {
    double degrees, radians;
    // M_PI is a common macro for Pi, but might require _USE_MATH_DEFINES on some compilers
    // For maximum portability, define PI manually or use acos(-1.0)
    #ifndef M_PI
    #define M_PI 3.14159265358979323846
    #endif

    printf("Enter angle in degrees: ");
    scanf("%lf", &degrees);

    // Convert degrees to radians
    radians = degrees * M_PI / 180.0;

    printf("%.2lf degrees is equal to %.4lf radians", degrees, radians);

    return 0;
}
SET SERVEROUTPUT ON;
DECLARE
  degrees_val  NUMBER := &Enter_Angle_in_Degrees;
  radians_val  NUMBER;
  PI           CONSTANT NUMBER := ACOS(-1); -- Oracle's way to get PI more accurately
BEGIN
  DBMS_OUTPUT.PUT_LINE('--- Degrees to Radians Conversion ---');
  DBMS_OUTPUT.PUT_LINE('Degrees: ' || degrees_val || '°');

  radians_val := degrees_val * PI / 180;

  DBMS_OUTPUT.PUT_LINE('Radians: ' || ROUND(radians_val, 4) || ' rad');
END;
/

Explanation

  • Java: Uses double for angle values. Scanner reads the degrees input. Math.PI provides the value of Pi.
  • Python: Reads input as a string and converts to float. Imports math module for math.pi.
  • C: Reads double input using scanf("%lf", ...) for the degrees. Uses M_PI (often available in math.h) or a custom definition for Pi. printf("%.4lf", ...) formats output.
  • Oracle: Implemented in PL/SQL. Uses NUMBER data type. ACOS(-1) is a standard way to get the value of Pi. Substitution variable for input.

Complexity Analysis

  • Time Complexity: O(1) - The number of arithmetic operations is constant.
  • Space Complexity: O(1) - A fixed number of variables are used.

Flowchart

graph TD
    A[Start] --> B[Get Degrees]
    B --> C[Set PI value]
    C --> D[Calculate Radians = Degrees * PI / 180]
    D --> E[Display Degrees and Radians]
    E --> F[End]

Sample Dry Run

Step Degrees PI Radians Description
Input 90.0 - - User enters 90.0
Process 90.0 3.14159 - PI is set
Process 90.0 3.14159 1.5708 Radians = 90.0 * PI / 180
Output - - 1.5708 Display "90.00° is 1.5708 rad"
End - - - Program terminates

Practice Problems

Easy

  • Modify the program to convert radians to degrees.
  • Convert angles between degrees, minutes, and seconds to decimal degrees.

Medium

  • Implement trigonometric functions (sin, cos, tan) without using built-in library functions, which will require understanding radian input.
  • Write a program that calculates the distance between two points on a sphere given their latitudes and longitudes (requires spherical trigonometry and radian conversion).

Hard

  • Develop a simple CAD program that uses radians for internal angle calculations.

"The only source of knowledge is experience." - Albert Einstein