Android的2D弧的碰撞检测 [英] android 2d arc collision detection

查看:390
本文介绍了Android的2D弧的碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旋转的弧线采用了android 2D图形绘制

i have a rotated arc drawn using android 2d graphics

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

在电弧的旋转游戏运行时,

我想知道我可以检测是否有其他的游戏对象(rects,圆)碰撞它 ??

这是我第一次写的一个游戏:)

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

我看到这样的事情在 http://hakim.se/experiments/html5/core / 01 /

在此先感谢

推荐答案

弧碰撞是稍硬再进行正常的碰撞,但使用布尔代数,你可以很容易地检查一个给定的一点是你的三分线内。

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

看看下面的图片。

有3个对象在这里。黑色的球体,这可视化你的圆弧,如果事情与它相撞,这可能是你的三分线内。上的黑色球体顶部的红色的球体,这可视电弧的内,如果事情是红球内,这绝对不是内部的弧。现在还有绿色三角形的可视化你的弧切断,绿色三角形里的任何东西也绝对不是在你的圆弧。

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.

测试,如果事情是内部的黑色球体很容易。 (向球&所述的中心对象的距离; =球体的半径)。同为红色球体。绿色三角形是有点棘手,你首先要构造此。找到你的圆弧的起点和终点的弧度。和由起始弧度转动一个单位矢量。然后转动最终弧度的单位向量。由2加长这两个矢量*的黑色球体的半径。现在,使用圆弧的中心点和两个向量与添加的中央位置为3点的三角形的位置。然后,您可以使用点三角形的碰撞求解器之一:的http://www.bing.com/search?q=point+triangle+collision&go=&form=QBLH&scope=web

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弧的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆