The Ellipse

• 03-20-2013, 10:35 PM
CuppaCoffee
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.
• 03-20-2013, 11:15 PM
SurfMan
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.
• 03-20-2013, 11:23 PM
doWhile
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.
• 03-20-2013, 11:47 PM
jim829
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
• 03-20-2013, 11:54 PM
CuppaCoffee
Re: The Ellipse
Quote:

Originally Posted by SurfMan
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
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
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!