groups

name language licence
Bearing between two points Objective-C Other



language: Objective-C
licence: Other

Bearing between two points

options: view full snippetsend to code collector
// inline, continuous version for radians
CGPoint startingPoint =:
CGPoint endingPoint =:

CGPoint originPoint = CGPointMake(endingPoint.x - startingPoint.x, endingPoint.y - startingPoint.y); 
float bearingRadians = atan2f(originPoint.y, originPoint.x);
bearingRadians = (bearingRadians > 0.0) ? bearingRadians : ((M_PI * 2.0) + bearingRadians); // remove discontinuity
// returns bearingRadians


// as stand-alone function to get bearing
	// get origin point to origin by subtracting end from start
	// get bearing in radians
	// convert to degrees
	 // correct discontinuity
	
(Continues...)