开发者

android 2d arc collision detection

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 m开发者_StackOverflow中文版e to write a game :)

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

Thanks in advance


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).

android 2d arc collision detection

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜