Oh, geometry! This Objective-c method cover a simple question: is a CGPoint inside a circle?
You need:
- http://objective-c-functions.blogspot.com/2013/06/compute-distance-between-two-points.html
/** Check whether a point lays inside a circle.
@param p Point to test.
@param circleCenter Center of the circle.
@param circleRadius Circle radius.
@return Returns true if point is within circle, false otherwise.
@see pointInCircleWithOrigin:ray:atAngle:
*/
+ (BOOL)isPoint:(CGPoint)p insideCircleWithCenter:(CGPoint)circleCenter radius:(CGFloat)circleRadius {
return ( [LMFunctions distanceIn2dFromPoint1:p toPoint2:circleCenter] <= circleRadius );
}
Download the ready-for-use source file (.m) of Test if a point is inside a circle
No comments:
Post a Comment