- (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
CGPoint pt;
float HALFSIDE = SIDELENGTH / 2.0f;
// normalize with centered origin
pt.x = (point.x - HALFSIDE) / HALFSIDE;
pt.y = (point.y - HALFSIDE) / HALFSIDE;
// x^2 + y^2 = radius
float xsquared = pt.x * pt.x;
float ysquared = pt.y * pt.y;
// If the radius < 1, the point is within the clipped circle
if ((xsquared + ysquared) < 1.0) return YES;
return NO;
}
本文介绍了一种简单有效的算法,用于判断一个给定点是否位于指定圆形区域内。该方法通过坐标转换将圆心置于坐标原点,并计算点到原点的距离来实现。如果该距离小于等于半径,则认为该点位于圆内。
121

被折叠的 条评论
为什么被折叠?



