Library contents

Java Math.toRadians

In Java, Math.toRadians converts an angle from degrees to radians by multiplying by π/180. A quarter turn is 90 degrees, or π/2 radians.

A simple example

Math.toRadians

  1. Start with 180 degrees
  2. Do this Convert a half-turn to radians
  3. Result π radians
A half-turn covers half the circle. In radians that angle is π, about 3.142.

Syntax

Java syntax
Math.toRadians(degrees)
JDK 21 method signatures (1)
public static double toRadians(double angdeg)
Run these examples in Java

Save one example at a time as Main.java. Use JDK 21.

java Main.java

Convert a half turn into radians

A drawing program describes the rotation of a wheel as a half turn. Its math routines consume radians, so convert that familiar rotation before passing it to the geometry code.

From the programdouble degrees = 180.0
Result3.142
Main.java

class Main {
    public static void main(String[] args) throws Exception {
        double degrees = 180.0;

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.toRadians(degrees)));
    }
}
Output
3.142

A half turn is 180 degrees, approximately 3.142 radians.

Advertisements

Feed a right angle into a drawing tool

An illustration tool receives a turn measured in degrees while its geometry routines expect radians. Convert the angle before using it to position a line on the drawing.

From the programdouble angle = 90.0
Result1.571
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        double angle = 90.0;

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.toRadians(angle)));
    }
}
Output
1.571

The drawing tool expects radians. Ninety degrees converts to approximately 1.571.

Animate a clock hand

An animator moves a hand thirty degrees around a dial. The rendering library expects radians for the rotation.

Given30
Worked result0.524 rad

Using 30 gives 0.524 rad for this measurement.

What to watch for

The displayed result is rounded. Keep the full returned value when doing further calculations.

Documentation for Math.toRadians