java - Collision detection : rounded object -
i'm developing java game (but dev. language doesn't matter) including rounded objects balls or pucks, , working on collisions. utilize timer, on every frame check if collision happens.
here graph represents top-right piece of object.
the center of object represented point [0,0], radius 10px , units pixels.
now if object (for example, obj_1
) square/diamond-shaped (blue line), find if 1 (obj_2
) collides have coordinates , checking math.abs(obj_1.x - obj_2.x) + math.abs(obj_1.y - obj_2.y) <= radius
know if there collision.
but problem more tricky circle shape (red line), because takes more space , occupied space not bounded straight line. of course of study have round values (for illustration in previous graph, if want check collision @ x = 2
have round y value looks 9.5 10). have no thought of how formula. help appreciated.
as mentioned implementation language not matter, give generic solution detecting collision of round objects.
also, gather, objects in scene circles. solution below not apply detecting collision between circle , other shape.
suppose have 2 circles c1 , c2. suppose corresponding radii c1.r , c2.r, , centers (c1.x,c1.y) , (c2.x, c2.y), next function tell whether c1 , c2 in collision
boolean arecolliding(circle c1, circle c2){ center_distance = sqrt((x1-x2)^2 +(y1-y2)^2); //this distance between centers of 2 circles. if((c1.r+c2.r) < center_distance) homecoming false; else homecoming true; }
this pseudo-code function homecoming true if circles colliding, false otherwise.
basically, function check whether distance between centers of circles greater sum of respective radius.
java collision-detection collision circle angle
No comments:
Post a Comment