0

I am working on a project involving iOS 7 UIDyanmics and and UIPushBehavior. As part of this I am trying to calculate the angle (expressed in radians) of an object based on two CGPoints. In my research I've found this answer but its expressed in Java.

Find the Angle between two Bearings

If someone has the Objective-C equivalent that would be fantastic.

Community
  • 1
  • 1

1 Answers1

0

Given two points...

#include <math.h>
CGPoint p0;
CGPoint p1;

The angle is the arctan of the quotient of the change in each dimension...

double dx = p0.x-p1.x;
double dy = p0.y-p1.y;

double angle = (dx)? atan(dy/dx) : NAN;

FYI, for next time, the SO culture strongly encourages questioners to show research, produce an attempt at a solution.

danh
  • 62,181
  • 10
  • 95
  • 136
  • Hi Dan, thanks for your code example and response. Since I posted this question I've been working through some math questions and have arrived at the same result. – Wayne Bishop Feb 24 '14 at 19:36
  • Glad to hear. The next step - if you deem the answer to be correct - is to mark it correct (by checking the little checkmark that appears at the upper left of this answer). – danh Feb 24 '14 at 19:42