Radian? You talk to your Momma with that mouth?

What the hell is a Radian?

Not sure either.  However, l discovered that this is what Objective-C and Swift use as a unit of measurement to rotate an object.   And I had to figure out what it was and how to determine the correct value.  Quick.

In the KoPilot App, there is a compass circle around the course value to graphically show the user which direction they are traveling.  To create this affect, I created a .PNG file of a circle with a small arrow indicating the direction of travel.  The arrow is at the top of the circle denoting North of 0 (zero) degrees.  To achieve the affect, I need to rotate the graphic the same number of degrees as the course value from the Location Manager.

And there became my problem.  Location Manager returns course from the GPS functions as a degree of the circle.  As a reminder, there are 360 degrees in a circle.  The function to rotate an object is “CGAffineTransformMakeRotation”, which takes GLFloat parameter of a Radian.

So, again, what the hell is a Radian and how to I get one if all I have is a course?

From Google:

 Radian: a unit of angle, equal to an angle at the center of a circle whose arc is equal in length to the radius.

 Ok, I’m still clueless.

Bottom line, without an explanation that saves the world using math, here is the formula to convert a course (degrees) to a Radian (what ever the hell that thing up there is)…

let toRadian:CGFloat =  CGFloat(Double( course ) / 180.0 * M_PI)

(yes, that is pi there at the end)

So we take that answer and feed it into the transform function and get:

self.imageCompass.transform = CGAffineTransformMakeRotation((toRadian ))

So, the object is being rotated the same number of degrees as the current course.  Since the object is a perfect circle with an arrow at 0 degrees, the result is that the arrow is now pointing in the direction of travel given that North is always at the top of the circle.

If your looking for a in depth understanding of Radian, I’m sorry to disappoint.  However, if you just need to convert a point of a circle or angle to Radian, I hope this helps.

The Adventure Continues

Share ...