Skip to content

Instantly share code, notes, and snippets.

@r3econ
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r3econ/9137844 to your computer and use it in GitHub Desktop.
Save r3econ/9137844 to your computer and use it in GitHub Desktop.
Degrees to radians conversion.
CGFloat DegreesToRadians(CGFloat degrees)
{
return degrees * M_PI / 180;
};
CGFloat RadiansToDegrees(CGFloat radians)
{
return radians * 180 / M_PI;
};
CGFloat DistanceBetweenTwoPoints(CGPoint pointA, CGPoint pointB)
{
CGFloat dx = pointB.x - pointA.x;
CGFloat dy = pointB.y - pointA.y;
return sqrt(dx*dx + dy*dy);
};
double AngleBetweenThreePoints(CGPoint pointA, CGPoint pointB, CGPoint pointC)
{
CGFloat a = pointB.x - pointA.x;
CGFloat b = pointB.y - pointA.y;
CGFloat c = pointB.x - pointC.x;
CGFloat d = pointB.y - pointC.y;
CGFloat atanA = atan2(a, b);
CGFloat atanB = atan2(c, d);
return atanB - atanA;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment