jam*_*mes 3 geometry cocoa-touch objective-c computational-geometry
给定圆的中心点和半径,我如何知道某个点(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
}
}
Run Code Online (Sandbox Code Playgroud)
此代码假定您处理子类视图中的圆.
| 归档时间: |
|
| 查看次数: |
2979 次 |
| 最近记录: |