Results 1 to 7 of 7
  1. #1
    aortell24 is offline Member
    Join Date
    Jun 2012
    Location
    St.louis, Missouri
    Posts
    49
    Rep Power
    0

    Default finding the overlap of two circles

    Hello, all I have a question. I have a problem for class to draw two overlapping circles which i have done no problem.But I get extra points if I can color in all three parts a different color the two circles are easy it's the the center or the overlap that I am having trouble with.i figured I would use fillArc to do the overlap but how do I find the parts that overlap.Thanks.

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    /**
     * Created with IntelliJ IDEA.
     * User: root
     * Date: 6/9/12
     * Time: 4:31 PM
     * To change this template use File | Settings | File Templates.
     */
    public class Quiz2A extends JFrame
    {
        Quiz2A()
        {
            NewPanel panel = new NewPanel();
            add(panel);
        }
    
        public static void main(String[] args)
        {
            Quiz2A frame = new Quiz2A();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.setSize(350,250);
            frame.setTitle("Quiz2B");
            frame.setLocationRelativeTo(null);
    
    
        }
     class NewPanel extends JPanel
     {
        protected void paintComponent(Graphics graphics)
        {
            graphics.drawOval(50,50,100,100);
            graphics.drawOval(125,50,120,120);
            //graphics.fillArc(100,50,50,20,20,75);
    
        }
     }
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: finding the overlap of two circles

    Perhaps the Graphics method setXORMode() will help. (Your commented out line ought to suggest that fillArc() won't help - even after all your trigonometry and stuff you get two overlapping arcs and you want the intersection. Same problem!)

  3. #3
    aortell24 is offline Member
    Join Date
    Jun 2012
    Location
    St.louis, Missouri
    Posts
    49
    Rep Power
    0

    Default Re: finding the overlap of two circles

    Thanks man I will look into that.

  4. #4
    aortell24 is offline Member
    Join Date
    Jun 2012
    Location
    St.louis, Missouri
    Posts
    49
    Rep Power
    0

    Default Re: finding the overlap of two circles

    Thank a lot man that worked perfectly.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: finding the overlap of two circles

    You're welcome.

    (In case anyone happens on the thread and wants a more complex approach... Java has a Shape interface which represent shapes - not surprisingly. There is a concrete implementation of Shape called Area which represents closed shapes like ellipses etc. This Area class actually allows you to do "constructive geometry" like unions, subtractions etc of one Area from another. And the Graphics2D class lets you render these areas filled and stroked however you like. The API docs have details, and Oracle's Tutorial describes an example in detail.)

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: finding the overlap of two circles

    Then there's the possibly simpler approach of Compositing Graphics. Filling the first circle, then successively filling the second with SRC_IN and SRC_OUT (with different colors for each of the three) would solve the stated problem.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: finding the overlap of two circles

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help determining if Circles overlap
    By quinnvanorder in forum New To Java
    Replies: 18
    Last Post: 04-22-2012, 06:58 AM
  2. How To Overlap Image
    By josephmacahasa in forum Java 2D
    Replies: 1
    Last Post: 08-19-2011, 09:58 AM
  3. overlap radius... help me..
    By tepong in forum New To Java
    Replies: 1
    Last Post: 08-21-2010, 08:41 PM
  4. Draw circles, select circles
    By cselic in forum Java 2D
    Replies: 2
    Last Post: 05-17-2010, 02:02 PM
  5. [SOLVED] Best way to overlap Images?
    By Krooger in forum AWT / Swing
    Replies: 3
    Last Post: 06-08-2009, 06:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •