Thread: Over lapping circles

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    114

    Over lapping circles

    I have different circles with their x,y co-ordinates and radius.What is the algorithm that I can find the area covered by the circles. does this need integral calculus? the problem description is here..http://uva.onlinejudge.org/index.php...m&problem=3208 . Which branches of programming should I know to solve this problem. Does the basics like loop,array,vector,map etc will help? or I need to know more than this!
    Last edited by Tamim Ad Dari; 05-01-2013 at 01:47 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Circular segment - Wikipedia, the free encyclopedia
    For two circles, construct a line (making a chord) between the two intersection points.
    From that, you can work out two areas for the segment of each circle, and adding these two together is the area of the overlap.

    The rest is just the area of two circles.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    114
    more than two? about 14-15?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Quote Originally Posted by Tamim Ad Dari View Post
    more than two? about 14-15?
    It's called a for loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    The problem is not finding the area of two overlapping circles (which is a straight formula). The problem appears when you have two overlapping circles (A and B), and you want to add a third one (C). You cannot simply add the area:

    C - overlap(C, A) - overlap(C, B)

    because you have to take into account overlap(A, B).
    Last edited by kmdv; 05-02-2013 at 02:20 PM.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I would work at it from reverse; figure out the total area that can be bombed.
    Then keep track of the un-bombed area after each bomb.
    No idea if it is easier or will work; but it seems like a way worth trying.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Jan 2013
    Posts
    114
    Owh.. I got that.. not an easy problem though...

  8. #8
    Registered User
    Join Date
    Jan 2013
    Posts
    114
    Not only overlap(C,A) and (C,B) will do... You have to also calculate overlap(A,B,C)...

  9. #9
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Are you allowed to use common APIs or libraries? For example make a full screen program that draws the circles as red in white background, capture a screenshot (from code), save screenshot in a bitmap and count the red pixels and you are done.

  10. #10
    Registered User
    Join Date
    Jan 2013
    Posts
    114
    nope... not allowed to do so..

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Here is an article related to a closed form (i.e. a formula) for computing area of overlap of three overlapping circles. That publication dates from 2006, so I doubt you'll find a lot of information about formulae for four or more overlapping circles.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  12. #12
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by C_ntua View Post
    Are you allowed to use common APIs or libraries? For example make a full screen program that draws the circles as red in white background, capture a screenshot (from code), save screenshot in a bitmap and count the red pixels and you are done.
    Isn't it obvious that it's a contest? You are usually limited to standard input/output and pure single-threaded computations.

    There are three approaches:
    1. Analytical - requires advanced math.
    2. Numerical - requires less math, but not as accurate.
    3. Per pixel checking - simple to implement, but extremely inefficient. In this case it would require 100 * 1000 * 100 * 1000 bits (precision to 3 decimal places), which is over one GB of memory.

    The approach 2 would since be preffered, through it requires basic knowledge of constructive solid geometry (limited to 2D in this case). All you need is to divide each circle into a sensible number of segments and implement sum operation. Having that, you need to compute the area of the constructed figures (note: there can be more than one). Both operations can be googled.
    Last edited by kmdv; 05-03-2013 at 07:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Circles and Computers
    By G4B3 in forum Tech Board
    Replies: 4
    Last Post: 11-29-2008, 09:23 AM
  2. Circles Anyone?
    By Nightsky in forum C Programming
    Replies: 5
    Last Post: 09-03-2006, 08:27 PM
  3. Firefox circles
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-20-2006, 09:49 AM
  4. Circles
    By Unregistered in forum Game Programming
    Replies: 0
    Last Post: 07-02-2002, 01:00 PM
  5. Drawing circles
    By chomper in forum Windows Programming
    Replies: 3
    Last Post: 05-07-2002, 12:37 PM