Results 1 to 5 of 5
Thread: The Ellipse
 03202013, 09:35 PM #1
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.
 03202013, 10:15 PM #2
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.
 03202013, 10:23 PM #3Moderator
 Join Date
 Jul 2010
 Location
 California
 Posts
 1,642
 Rep Power
 7
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.
 03202013, 10:47 PM #4Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 3,618
 Rep Power
 5
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,
JimThe Java™ Tutorial  SSCCE  Java Naming Conventions
Poor planning our your part does not constitute an emergency on my part.
 03202013, 10:54 PM #5
Re: The Ellipse
That's a very detailed article. I'll have to give that a very thorough read. Thanks for the guidance!
That seems to be on the right track. I'll give this some consideration along with SurfMan's suggestion.
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

Rectangle/Ellipse won't draw
By Danieldcc in forum SWT / JFaceReplies: 1Last Post: 03072012, 07:51 AM 
JPanel and Oval/Ellipse Problems
By PorgrammingNoob117 in forum AWT / SwingReplies: 1Last Post: 05042011, 09:59 PM 
drawing ellipse by drawline method?
By hopey in forum Java 2DReplies: 8Last Post: 04182009, 11:52 PM 
How to Draw Ellipse in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06232008, 11:13 PM 
GradientPaint Ellipse
By Java Tip in forum java.awtReplies: 0Last Post: 06212008, 08:48 PM
Bookmarks