给定圆的中心点和半径,如何知道某个点(x,y)是否在圆内?有人知道吗?谢谢。
给定圆的中心点和半径,如何知道某个点(x,y)是否在圆内?有人知道吗?谢谢。
最初您要求的是Objective-C。
CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
{
CGFloat dx = point2.x - point1.x;
CGFloat dy = point2.y - point1.y;
return sqrt(dx*dx + dy*dy );
};
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point = [[touches anyObject] locationInView:self];
CGFloat distance = DistanceBetweenTwoPoints(self.circleCenter, point);
if(distance < self.radius){
//inside the circle
}
}