I have a circle and I want to know the exact position of a CGPoint that lays at a certain angle and distance from origin.
Using this convenient Objective-C method is not such a pain.
/** Returns the coordinates of a point located inside a circle at certain ray and angle.
Angle must be in radians.
@param origin Center of the circle.
@param ray Distance along radius between center and point location.
@param angle Angle where point is located.
@return Returns the coordinates X and Y of the point.
@see isPoint:insideCircleWithCenter:radius:
*/
+ (CGPoint)pointInCircleWithOrigin:(CGPoint)origin ray:(CGFloat)ray atAngle:(CGFloat)angle {
return CGPointMake(origin.x + ray * cosf(angle), origin.y + ray * sinf(angle));
}
Download the ready-for-use source file (.m) of Get the coordinates of a Point inside a Circle
No comments:
Post a Comment