circle - rectangle collision in 2D, most efficient way
        Posted  
        
            by 
                john smith
            
        on Game Development
        
        See other posts from Game Development
        
            or by john smith
        
        
        
        Published on 2012-12-04T09:48:40Z
        Indexed on 
            2012/12/04
            11:31 UTC
        
        
        Read the original article
        Hit count: 374
        
collision-detection
Suppose I have a circle intersecting a rectangle, what is ideally the least cpu intensive way between the two?
- method A - calculate rectangle boundaries
- loop through all points of the circle and, for each of those, check if inside the rect.
 
- method B - calculate rectangle boundaries
- check where the center of the circle is, compared to the rectangle
- make 9 switch/case statements for the following positions: - top, bottom, left, right
- top left, top right, bottom left, bottom right
- inside rectangle
 
- check only one distance using the circle's radius depending on where the circle happens t be. 
 
I know there are other ways that are definitely better than these two, and if could point me a link to them, would be great but, exactly between those two, which one would you consider to be better, regarding both performance and quality/precision?
Thanks in advance.
© Game Development or respective owner