Library contents

Kotlin java.lang.Math.toDegrees

In Kotlin, java.lang.Math.toDegrees converts an angle from radians to degrees by multiplying by 180/π. Half a turn is π radians, or 180 degrees.

A simple example

java.lang.Math.toDegrees

  1. Start with π radians
  2. Do this Convert a half-turn to degrees
  3. Result 180°
A full turn is 2π radians or 360 degrees. Half a turn is 180 degrees.

Syntax

Kotlin syntax
java.lang.Math.toDegrees(radians)
Run these examples in Kotlin

Save one example at a time as Lesson.kt. Use Kotlin 2.2 on JDK 21.

kotlinc Lesson.kt -include-runtime -d lesson.jar
java -jar lesson.jar

Label a quarter turn in degrees

A navigation wheel makes one quarter turn. Convert the angle from radians to degrees before giving it to the display component that labels the wheel.

From the programval radians = 1.5707963267948966
Result90.000
Lesson.kt

fun main() {
    val radians = 1.5707963267948966

    System.out.printf(java.util.Locale.ROOT, "%.3f%n", (java.lang.Math.toDegrees(radians)).toDouble())
}
Output
90.000

One quarter turn is approximately 1.571 radians and displays as 90 degrees.

Advertisements

Label a turn on a navigation dial

A dial calculation produces an angle in radians, while the person using the dial reads degrees. Convert a familiar turn to confirm the scale on the display.

From the programval angle = 3.141592653589793
Result180.000
Lesson.kt
fun main() {
    val angle = 3.141592653589793

    System.out.printf(java.util.Locale.ROOT, "%.3f%n", (java.lang.Math.toDegrees(angle)).toDouble())
}
Output
180.000

A half turn is pi radians, which the dial displays as 180 degrees.

Label a dial rotation

A drawing tool rotates a pointer by one radian. A student wants to annotate the same turn in degrees.

Given1
Worked result57.3 °

Using 1 gives 57.3 ° for this measurement.

What to watch for

Converting the unit does not wrap an angle into a single revolution.

Documentation for java.lang.Math.toDegrees