Does anyone know how to check if an object is in an oval drawn on a java applet screen.
I'm not sure of the math needed to check this, if you post a code can you please have it "System.out.println("In the oval");"
Printable View
Does anyone know how to check if an object is in an oval drawn on a java applet screen.
I'm not sure of the math needed to check this, if you post a code can you please have it "System.out.println("In the oval");"
If the oval is an instance of Ellipse2D, it will have 'contains' methods for single points and rectangular areas.
Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable techniques to solve it...
A. Aho and J. Ullman
What? That doesn't help me at all. I don't understand what your getting at could you give me an example please?
Instead of playing "guess my question" why don't you state exactly what you want to know.
Why do you say circle in the topic and oval in the question? What is it exactly and how is it represented.
What's the nature of the "object" you're talking about? How is it represented?
Be specific and you get specific replies.
Oh. OK.
Quote:
I don't understand what your getting at could you give me an example please?
It is better to have an approximate answer to the right question than an exact answer to the wrong one...Code:Component object = getObject();
Ellipse2D oval = getOval();
// check to see if object is inside oval
Rectangle bounds = object.getBounds();
boolean isInside = oval.contains(bounds.x, bounds.y, bounds.height, bounds.width);
J. Tukey
And just in case you aren't using that class, you said:
The 'math' needed to do this is simple: You cast a ray, any direction, from the point in question (usually done to the right). If the ray / vector intersects the boundary of the circle (i.e. at some point lies on the circle) only once, then it is inside the circle. If it intersects it twice, or not at all then it is outside the circle.Quote:
I'm not sure the math needed to check this...
dlorde has given a java class that does this. If you want a code example you could just look at the source code for the java.awt.geom.Ellipse2D classes contains() method and see how that class does it.Quote:
Clarfying what you suggest should be a plus
Mayb a piece of code snip you pick up somewhere for example
I suppose at least the poster asking for code didn't use the OP's line of "What? That doesn't help me at all."
The fun part is trying to optimize the algorithm that tries to determine this, given an array of points for a polygon.
I duel majored in Pure Mathematics and Computer Science. This is the type of stuff I would rather be doing than coding stupid webapps for a bank :o However, for some reason these companies hiring guys to do complex math and embedded c++ code seem to think that paying 20k below market value for a Java developer is going to net them top candidates. I wonder how their simulator is coming along? :rolleyes:
Sorry Deliverance, rereading my post I realized that I didn't word it quite right. What I meant to convey is that locally they are paying say 50k / year for C++, Simulation software, embedded C developers and over 70k / year for Java developers. So, the guys doing the harder, more complex jobs get paid less. I've seen this paradigm before... :D