Head on Collision
By E.Hooijmeijer
1 Inleiding
Na de zoveelste Command&Conquer kloon besluit EA eindelijk eens wat nieuws uit te brengen :
ArkaPong - en combi van het klassieke Pong en Arkanoid. Geen geweldig idee, maar het is weer eens
wat anders. Essentieel bij ArkaPong is een correcte botsings detectie tussen de ballen. Raad
eens wie dat klusje mag klaren :-)
2 Opdracht
Implementeer de routine 'collision' welke true moet terug geven wanneer de 2 gegeven ballen
in botsing zijn. In botsing betekent dat of de randen van de bal elkaar raken of dat ze elkaar
deels overlappen.
3 Voorbeeld
Bal 1 heeft een straal van 5 pixels en staat op positie 0,0.
Bal 2 heeft een straal van 5 pixels en staat op positie 10,10.
De afstand tussen de twee middelpunten is 14.14 pixels. Ze botsen niet.
Bal 1 heeft een straal van 10 pixels en staat op positie 0,0.
Bal 2 heeft een straal van 5 pixels en staat op positie 10,10.
De afstand tussen de twee middelpunten is 14.14 pixels. Ze botsen nu wel.
4 Tips
- Een gevalletje middelbare school dejavu.
- gelukkig bevat java.awt.geom.Point2D handige routines.
Test case 1 : Too bad, Just missed them.
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 5.0 and speed 2.0,2.0
- a blue one starting at 90.0 10.0 with radius 5.0 and speed -3.0,3.0
Determine for each of the 25 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 2 : Full Frontal
Given 2 balls :
- a green one starting at 10.0 40.0 with radius 5.0 and speed 4.0,0.0
- a blue one starting at 90.0 40.0 with radius 5.0 and speed -4.0,0.0
Determine for each of the 25 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 3 : A close Shave
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 5.0 and speed 4.0,0.0
- a blue one starting at 90.0 18.0 with radius 5.0 and speed -4.0,0.0
Determine for each of the 25 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 4 : High speed maniac
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 5.0 and speed 4.0,0.0
- a blue one starting at 50.0 18.0 with radius 5.0 and speed 0.0,0.0
Determine for each of the 20 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 5 : High speed maniacs
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 5.0 and speed 4.0,0.0
- a blue one starting at 90.0 18.0 with radius 5.0 and speed -4.0,0.0
Determine for each of the 20 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 6 : Small speed maniac
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 5.0 and speed 1.0,0.0
- a blue one starting at 90.0 18.0 with radius 2.0 and speed -4.0,0.0
Determine for each of the 20 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 7 : Small speed maniacs
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 2.0 and speed 4.0,0.0
- a blue one starting at 90.0 14.0 with radius 2.0 and speed -4.0,0.0
Determine for each of the 20 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 8 : Jaywalking
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 5.0 and speed 3.0,3.0
- a blue one starting at 90.0 10.0 with radius 5.0 and speed -3.0,3.0
Determine for each of the 25 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.
Test case 9 : Wayjalking
Given 2 balls :
- a green one starting at 10.0 10.0 with radius 5.0 and speed 3.0,2.0
- a blue one starting at 90.0 10.0 with radius 9.0 and speed -2.0,3.0
Determine for each of the 25 frames if the two balls will collide with each other.
Expected result : true when the balls are colliding, false if the're not.