PDA

View Full Version : Need help asap



bobkuka
Oct 15th, 2011, 01:47 AM
i really dont understand this java problem, i did all i could and i still dont get it plz help me. Its my practice test for tomorrow and i dont get this.

In video games it is often required to be able to determine if two balls have collided. Create a program which accepts the radius and the center (x,y) of each ball and states whether the two balls have collided. Hint: Draw and label all the known information for situations (2) when the balls have collided and when they have not collided.

Old Pedant
Oct 15th, 2011, 02:19 AM
JAVA? Or javeSCRIPT?? This is the javaSCRIPT forum. About the only simiilarity between JAVA and javaSCRIPT are the first 4 letters of their names.

Having said that...

The actual problem here is kind of independent of any kind of language.

This is a simple geometry problem.

Think about it:

If two balls are touching, how far apart are their centers? No matter *HOW* they are touching?

Suppose the radius of one ball is 2 inches and the other is 1 inch. If the centers of the two balls are only 1 inch apart, can you draw a picture of them?

Do it. Get a piece of paper. Put a dot on it. Put another dot on it that is exactly one inch away, in any direction you choose. Now use a compass and draw one circle around the first dot that has a radius of 1 inch. Use the compass to draw a circle around the other dot that has a radius of two inches. What do you notice about the two circles?

Repeat the experiment when the two dots are 4 inches apart.

Repeat the experiment when the two dots are 2 inches apart.

Hmmm...

Beginning to get an idea?

So how far apart *will* the center dots be if the two circles are *JUST* touching?

Okay, now that you know that, how would you determine whether two circles (balls) were touching if you knew where their two centers were?

HINT: Pythagorean theorem.

Old Pedant
Oct 15th, 2011, 02:32 AM
MrHoo: I would assume that the directions he gave us were quoted from the assignment
Create a program which accepts the radius and the center (x,y) of each ball and states whether the two balls have collided.
If the center is given with only (x,y) then I think we can assume this is just a 2D problem.