Created
April 10, 2015 09:13
-
-
Save densa/3fb0fea6f135e5412aab to your computer and use it in GitHub Desktop.
findPointOnTangentOnCircleWithCenter
This file contains hidden or 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
+(double)distanceBetweenPoint:(CGPoint)pointA andAnotherPoint:(CGPoint)pointB | |
{ | |
return sqrt((pointA.x - pointB.x)*(pointA.x - pointB.x) + (pointA.y - pointB.y)*(pointA.y - pointB.y)); | |
} | |
+(NSArray *)findPointOnTangentOnCircleWithCenter:(CGPoint)center Radius:(double)radius pointOnTangent:(CGPoint)point | |
{ | |
double dx = center.x - point.x; | |
double dy = center.y - point.y; | |
double distance = [EXMathBrain distanceBetweenPoint:center andAnotherPoint:point]; | |
double alfa = atan2(dy, dx); | |
double beta = asin(radius/distance); | |
double segmentLen = sqrt(distance*distance - radius*radius); | |
NSMutableArray *results = [NSMutableArray arrayWithCapacity:2]; | |
dx = cos(alfa+beta)*segmentLen; | |
dy = sin(alfa+beta)*segmentLen; | |
[results addObject:[NSValue valueWithCGPoint:CGPointMake(point.x+dx, point.y+dy)]]; | |
dx = cos(alfa-beta)*segmentLen; | |
dy = sin(alfa-beta)*segmentLen; | |
[results addObject:[NSValue valueWithCGPoint:CGPointMake(point.x+dx, point.y+dy)]]; | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment