Library contents

Kotlin kotlin.math.sin

In Kotlin, kotlin.math.sin takes an angle in radians and returns its sine. In a right triangle, sine is the opposite side divided by the hypotenuse.

A simple example

kotlin.math.sin

  1. Start with 0 radians
  2. Do this Find the vertical component
  3. Result 0
Picture a unit line lying flat. Its tip has zero height, so the sine of zero is zero.
Lesson.kt
fun main() {
    println(kotlin.math.sin(0.0))
}
Output
0.0

Syntax

Kotlin syntax
kotlin.math.sin(angle)
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

Find the vertical share of a ladder

A maintenance team is sketching a ladder or lifting arm against a wall. Use the known length and angle or height to recover the missing dimension and check the units before entering it in the drawing.

Given30° above the floor · 0.524 radians, rounded
Result0.500
Lesson.kt

fun main() {
    val angle = 0.5235987755982988

    System.out.printf(java.util.Locale.ROOT, "%.3f%n", (kotlin.math.sin(angle)).toDouble())
}
Output
0.500

At 30 degrees, the vertical rise is half the length of the ladder. The input is 30 degrees expressed in radians.

Advertisements

Check a vertical lifting arm

A hoist diagram shows an arm pointing straight up. Evaluate that limiting position to check how much of its length contributes to the vertical component.

Given90° above the floor
Result1.000
Lesson.kt
fun main() {
    val angle = 1.5707963267948966

    System.out.printf(java.util.Locale.ROOT, "%.3f%n", (kotlin.math.sin(angle)).toDouble())
}
Output
1.000

An arm at a right angle to the floor directs its whole length vertically.

Measure a scenery ladder

A theatre student builds a scale drawing of a ladder for a stage set. Its length is 4 m and its angle to the floor is 30°. How high is its tip in the drawing’s full-size dimensions?

Given4 m at 30°
Worked result2.00 m

Multiply the length by the sine of the angle measured from the floor.

Code and output in Kotlin
Kotlin source
fun main() {
    val base = 0.0
    val length = 4.0
    val angle = Math.toRadians(30.0)
    System.out.printf(java.util.Locale.ROOT, "%.2f m%n", base + length * kotlin.math.sin(angle))
}
Output
2.00 m

Locate a Ferris wheel cabin

A wheel in an animation has an 8 m radius and its hub is 10 m above the ground. When the cabin is 30° above the horizontal on its way up, the animator needs its height above ground.

GivenHub 10 m · radius 8 m · 30°
Worked result14.00 m

The cabin is 4 m above the hub. Add that rise to the hub height.

Code and output in Kotlin
Kotlin source
fun main() {
    val base = 10.0
    val length = 8.0
    val angle = Math.toRadians(30.0)
    System.out.printf(java.util.Locale.ROOT, "%.2f m%n", base + length * kotlin.math.sin(angle))
}
Output
14.00 m

What to watch for

Convert a degree measurement to radians before calling a trigonometric function.

Documentation for kotlin.math.sin