Thursday, August 25, 2011

Find intersecting area of 2 CGRects























If you have 2 rectangles overlapping each other and you want to find the area of the intersecting area which is shown in the picture with checks pattern. You can find width and height of intersection area. Since area is a rectangle, you can simply do width x height.

       CGRect b=CGRectMake(40, 50, 240, 150);
    CGRect c=CGRectMake(100, 125, 80, 275);
    
    
     CGRect i=CGRectIntersection(c, b);
    
    NSLog(@"(%.0f,%.0f,%.0f,%.0f)",CGRectGetMinX(i),CGRectGetWidth(i),CGRectGetMinY(i),CGRectGetHeight(i));



If this is not what you were looking for CGRect, try this comprehensive LIST.

3 comments:

  1. Nice post! Can’t wait for the next one. Keep stuff like this coming.
    Asus Laptops

    ReplyDelete
  2. nice blogs
    Videocon Telecommunications Limited, a Videocon group company offers GSM mobile services GSM service under the brand name Videocon. The services are already up and running in Punjab*, Gujarat, Haryana, Madhya Pradesh and soon will be present across the country.

    ReplyDelete