Objective-C

Calculate Distance Between Two Points in Objective-C

Monday, June 30th, 2008

How to calculate the distance between two points.

CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
{
CGFloat dx = point2.x - point1.x;
CGFloat dy = point2.y - point1.y;
return sqrt(dx*dx + dy*dy );
};

How to Convert Degrees to Radians, Radians to Degrees in Objective-C

Monday, June 30th, 2008

CGFloat DegreesToRadians(CGFloat degrees)
{
return degrees * M_PI / 180;
};

CGFloat RadiansToDegrees(CGFloat radians)
{
return radians * 180 / M_PI;
};

Useful Trigonometry Functions in Objective-C

Monday, June 30th, 2008

During our latest project, we faced a number of problems that Trigonometry solved rather nicely. I found a number of Trigonometry resources, but not any that focused on how to implement these concepts in Objective-C. We thought it would be good to post some of the more helpful functions.