4

i have a rotated arc drawn using android 2d graphics

c.drawArc(new RectF(50, 50, 250, 250), 30, 270, true, paint);

the arc will rotate while the game is running ,

i wanna know how i can detect if any other game objects(rects ,circles) collide with it ??

this is the first time for me to write a game :)

i saw something like this in http://hakim.se/experiments/html5/core/01/

Thanks in advance

ibmkhd
  • 799
  • 2
  • 14
  • 25

1 Answers1

7

Arc collisions are slightly harder then normal collisions, but using boolean algebra you can easily check if a given point is inside your arc.

Take a look at the following picture.

There are 3 objects here. The black sphere, this visualizes your arc, if something collides with it, it might be inside your arc. The red sphere on top of the black sphere, this visualizes the 'inside' of the arc, if something is inside the red sphere, it's definately not 'inside' the arc. Now there is also the green triangle that Visualizes the 'cut-off' of your arc, anything inside the green triangle is also definately not in your arc.

Testing if something is inside the black sphere is easy. (object's distance to center of sphere <= radius of sphere). Same for the red sphere. The green triangle is a bit tricky, you first have to construct this. Find the start and end radians of your arc. and rotate a unit vector by start radians. Then rotate a unit vector by end radians. Lengthen both these vectors by 2 * the radius of the black sphere. Now use the center point of your arc and the positions of two vectors with added the center position as the 3 points of the triangle. You can then use one of the point-triangle collision solvers: http://www.bing.com/search?q=point+triangle+collision&go=&form=QBLH&scope=web

So remember: collision with arc = (collision with black sphere) && !(collision with red sphere) && !(collision with green triangle).

ARC Collision

Roy T.
  • 9,429
  • 2
  • 48
  • 70
  • Thanks so much ,i will try to implement this in android and tell you what happens with me. – ibmkhd Jun 11 '11 at 09:19
  • For my case i made in rectangle instead of the triangle because the curve is exactly a half circle and this is work fine with me ,Thanks for your help – ibmkhd Jun 12 '11 at 07:04
  • This is an Android question, but the concept is the same in all languages. This helped me with mine JS Canvas. +1 – call-me Jan 21 '16 at 15:46
  • Ok, wow... nicely elegant solution, as well as intuitive to write for a programmer. Guess I'll use this rather than continue my research into... intersecting two circles, then checking for overlap between the intersection points and the arc-angles, even though that would also work. – James Apr 05 '16 at 18:34