Convert degrees to radians and radians to degrees

In real life, we are used to degrees and in programming, we deal mostly with radians. If you are dealing with drawing specifically arc and circles you will come across situations where you have to toggle between degrees and radians and at other times between radians to degrees.

Relationship between Degrees and Radian

Relation between degrees and radians

The above image shows you the relationship between degrees and radians. Once we have understood that π = 180º i.e 1º = π/180º we are ready for our next step making a function to convert radians to degrees and to convert degrees to radians

Convert degrees to radians

func toRad(degree: Double) -> Double {
    return degree * .pi / 180
}

Convert radians to degree

func toDegree(radians: Double) -> Double {
    return radians * 180 / .pi
}

Hope this helps!!!

A pat on the back !!