-
February 6th, 2010, 10:33 PM
#1
Checking objects in a circle
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");"
-
February 7th, 2010, 01:16 PM
#2
Re: Checking objects in a circle
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
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
February 7th, 2010, 10:21 PM
#3
Re: Checking objects in a circle
What? That doesn't help me at all. I don't understand what your getting at could you give me an example please?
-
February 8th, 2010, 01:45 AM
#4
Re: Checking objects in a circle
Originally Posted by B.Star117
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.
Last edited by nuzzle; February 8th, 2010 at 01:54 AM.
-
February 8th, 2010, 05:19 AM
#5
Re: Checking objects in a circle
Originally Posted by B.Star117
What? That doesn't help me at all.
Oh. OK.
I don't understand what your getting at could you give me an example please?
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);
It is better to have an approximate answer to the right question than an exact answer to the wrong one...
J. Tukey
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
February 8th, 2010, 09:21 AM
#6
Re: Checking objects in a circle
And just in case you aren't using that class, you said:
I'm not sure the math needed to check this...
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.
-
February 8th, 2010, 09:31 AM
#7
Re: Checking objects in a circle
Originally Posted by ProgramThis
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.
Reading your math suggestions makes me want to pull out my university books again. I'm starting to get rusty. These type of solutions don't come to my mind anymore.
------
If you are satisfied with the responses, add to the user's rep!
-
February 8th, 2010, 09:56 AM
#8
Re: Checking objects in a circle
Originally Posted by ProgramThis
... 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.
Clarfying what you suggest should be a plus
Mayb a piece of code snip you pick up somewhere for example
-
February 8th, 2010, 12:07 PM
#9
Re: Checking objects in a circle
Clarfying what you suggest should be a plus
Mayb a piece of code snip you pick up somewhere for example
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.
-
February 8th, 2010, 02:33 PM
#10
Re: Checking objects in a circle
Originally Posted by keang
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.
I suspect the OP lacks the initiative...
Experience is a poor teacher: it gives its tests before it teaches its lessons...
Anon.
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
February 8th, 2010, 05:11 PM
#11
Re: Checking objects in a circle
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."
-
February 9th, 2010, 01:24 PM
#12
Re: Checking objects in a circle
Originally Posted by Deliverance
Reading your math suggestions makes me want to pull out my university books again. I'm starting to get rusty. These type of solutions don't come to my mind anymore.
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 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?
-
February 9th, 2010, 02:05 PM
#13
Re: Checking objects in a circle
Originally Posted by ProgramThis
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 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?
Reminds me of what nuzzle was saying in another post with java being a managed language that is 'safe' that they assume anyone can do a good job at architecting and implementing a large system properly.
------
If you are satisfied with the responses, add to the user's rep!
-
February 9th, 2010, 03:41 PM
#14
Re: Checking objects in a circle
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|