Results 1 to 5 of 5

Thread: The Ellipse

  1. #1
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default The Ellipse

    Just a quick and simple question. Let's say you had a rectangle with a moving ellipse inside. If the ellipse hits any of the walls you can get it to 'bounce' just by testing boundaries (if the top of the ellipse comes into contact with the top of the rectangle, the ellipse with move in the opposite direction). That's simple enough. But what if the situation was a big ellipse with a small ellipse inside? How do you check boundaries between two circular objects? I know Ellipse.2D is declared with a few variables for x position, y position, width, and height, but there's nothing said about circumference or any of that. Some help or guidance would be much appreciated. I hope this issue was stated clearly.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: The Ellipse

    This will get pretty "mathy", but on Stackoverflow they have an article that might help you on your way: java - How to detect overlapping circles and fill color accordingly? - Stack Overflow

    I know it's not overlapping, but the method of distance and radii looks like a place to start.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: The Ellipse

    I don't think there is anything within the API that you can use to determine this directly. But mathematically, you have the center of both ellipses, so first find the distance between both centers (call it l2). Next, find the points on the surface of each ellipse that lie on this line (you can use the ellipse equations and polar coordinates to do so). The distance between the larger ellipse center and its surface point should be larger than l2 + 2x the distance between the smaller ellipse center and its surface point if the inner ellipse is inside.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: The Ellipse

    I was thinking about the general case. Consider the case where the smaller ellipse's major axis is just a bit shorter in length than the larger ellipses' minor axis. The ellipse centers don't change relative to one another with respect to each of the individual ellipses rotational orientation. So as the smaller ellipse moves inside the larger one, depending on its orientation I believe some more calculations will be required. Or am I missing something here?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: The Ellipse

    Quote Originally Posted by SurfMan View Post
    This will get pretty "mathy", but on Stackoverflow they have an article that might help you on your way: java - How to detect overlapping circles and fill color accordingly? - Stack Overflow

    I know it's not overlapping, but the method of distance and radii looks like a place to start.
    That's a very detailed article. I'll have to give that a very thorough read. Thanks for the guidance!

    Quote Originally Posted by doWhile View Post
    I don't think there is anything within the API that you can use to determine this directly. But mathematically, you have the center of both ellipses, so first find the distance between both centers (call it l2). Next, find the points on the surface of each ellipse that lie on this line (you can use the ellipse equations and polar coordinates to do so). The distance between the larger ellipse center and its surface point should be larger than l2 + 2x the distance between the smaller ellipse center and its surface point if the inner ellipse is inside.
    That seems to be on the right track. I'll give this some consideration along with SurfMan's suggestion.

    Quote Originally Posted by jim829 View Post
    I was thinking about the general case. Consider the case where the smaller ellipse's major axis is just a bit shorter in length than the larger ellipses' minor axis. The ellipse centers don't change relative to one another with respect to each of the individual ellipses rotational orientation. So as the smaller ellipse moves inside the larger one, depending on its orientation I believe some more calculations will be required. Or am I missing something here?

    Regards,
    Jim
    It's sounds like you're on the right track. I agree, a lot of mathematical calculations are going to have to come into play and I was seeing what you all would think about this. Thank you kindly for all the replies, everyone. Right at the moment there's no project I've started that has this problem, but I'll be dealing with cases like these very soon. I'll take this to heart!

Similar Threads

  1. Rectangle/Ellipse won't draw
    By Danieldcc in forum SWT / JFace
    Replies: 1
    Last Post: 03-07-2012, 07:51 AM
  2. JPanel and Oval/Ellipse Problems
    By PorgrammingNoob117 in forum AWT / Swing
    Replies: 1
    Last Post: 05-04-2011, 09:59 PM
  3. drawing ellipse by drawline method?
    By hopey in forum Java 2D
    Replies: 8
    Last Post: 04-18-2009, 11:52 PM
  4. How to Draw Ellipse in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:13 PM
  5. GradientPaint Ellipse
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 08:48 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
  •