3

원의 중심점과 반지름을 감안할 때 어떤 점 (x, y)이 원 안에 있는지 어떻게 알 수 있습니까? 누구든지 그것을 압니까? 감사.원 안에 점

+4

일반적인 질문은 태그와 관련이 없습니다 .... 그리고 쉽게 검색 할 수 있습니다 –

+2

간단히 말해서 : [중심에서부터 점까지의 거리를 결정하십시오] (http://en.wikipedia.org/wiki/Pythagoras#Pythagorean_theorem), 반경과 비교하십시오. – Znarkus

+0

특히 Objective-C는 아니지만 도움이됩니다. 함수를 매우 쉽게 변환 할 수 있어야합니다 : [http://stackoverflow.com/questions/481144/how-do-you-test-if-a-point-is-inside-a-circle](http:/) /stackoverflow.com/questions/481144/how-do-you-test-if-a-point-is-inside-a-circle) –

답변

8

원래 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 
    } 
} 

이 코드는 서브 클래 싱 된보기 내에서 원을 처리한다고 가정합니다.

+0

감사합니다. 정말 감사드립니다. – james

+0

포인트를 감지하는 방법은 섹터 안에 있거나 없는가? – Johnykutty