Created
July 4, 2014 08:44
-
-
Save nsdevaraj/f968480d5d8616c8f4ec to your computer and use it in GitHub Desktop.
Triangulate with 3 beacon points - y with division by zero to be rectified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGPoint)getCoordinateWithBeaconA:(CGPoint)a beaconB:(CGPoint)b beaconC:(CGPoint)c distanceA:(CGFloat)dA distanceB:(CGFloat)dB distanceC:(CGFloat)dC { | |
CGFloat W, Z, x, y, y2; | |
W = dA*dA - dB*dB - a.x*a.x - a.y*a.y + b.x*b.x + b.y*b.y; | |
Z = dB*dB - dC*dC - b.x*b.x - b.y*b.y + c.x*c.x + c.y*c.y; | |
x = (W*(c.y-b.y) - Z*(b.y-a.y)) / (2 * ((b.x-a.x)*(c.y-b.y) - (c.x-b.x)*(b.y-a.y))); | |
y = (W - 2*x*(b.x-a.x)) / (2*(b.y-a.y)); | |
//y2 is a second measure of y to mitigate errors | |
y2 = (Z - 2*x*(c.x-b.x)) / (2*(c.y-b.y)); | |
y = (y + y2) / 2; | |
return CGPointMake(x, y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source not work