旋转箭时,它的飞行 [英] Rotate a Arrow when it's flying

查看:86
本文介绍了旋转箭时,它的飞行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要根据抛运动斜箭头飞。我使用的功能: X =(vo.cos(阿尔法))T。 Y =(vo.sin(阿尔法))T-g.t.t / 2; 我已计算出的箭头的切线的角度。 标签的β=(vo.sin(阿尔法)-g.t)/(vo.cos(阿尔法)) 我根据旋转方向(α - 测试版)的箭头移动一样自然。 这是我的功能onDarw():

I have an arrow flying according throwing motion oblique . I use function : x=(vo.cos(alpha)).t; y=(vo.sin(alpha)).t-g.t.t/2; and I have calculated the tangent angle of the arrow . tag beta =(vo.sin(alpha)-g.t)/(vo.cos(alpha)) and I rotate arrow according (alpha - beta) for arrow move same with natural. This is my function onDarw():

保护无效的OnDraw(帆布油画){

protected void onDraw(Canvas canvas) {

    canvas.drawColor(Color.WHITE);
    Matrix matrix=new Matrix();
    degree= (float) (Math.atan(y1/x1)*180/Math.PI);
    matrix.postRotate( degree,x,y);
    matrix.postTranslate(x,y);
    alpha=(float) ((90-degree)*Math.PI/180);
    canvas.drawBitmap(bmp, matrix, null);
    if(k==1){
        //y+=20;
        //x=(float) ((-g)*Math.pow(y, 2)/(2*vo*vo*Math.pow(Math.cos(alpha), 2))+Math.tan(alpha)*y/10);
        y=(float) (vo*Math.cos(alpha)*t);
        x=(float) (vo*Math.sin(alpha)*t-(g*t*t)/2);
        beta= (float) ((Math.atan((vo*Math.sin(alpha)-g*t)/vo*Math.cos(alpha)))*Math.PI/180);
        matrix.postRotate((alpha-beta ),y ,x );
        matrix.postTranslate(y,x);
        t++;
    }

K = 1就是我要当我实现action_up,箭头飞。但是这并不成功,箭头招不自然。 请帮我。

k=1 is I want When I implement action_up ,arrow will fly .But it don't successful , the arrow move don't natural. Please help me.

推荐答案

vBasically,你应该假设箭头导向切向其行程的弧线。这意味着,它的角度将是其x速度到其y速度之比的反正切。

vBasically, you should assume that the arrow is oriented tangentially to the arc of its travel. That means that its angle will be the arctan of the ratio of its x velocity to its y velocity.

因此​​,根据它们的值跟踪x和y速度在每个时间步长,计算新的角度

So, keep track of the x and y velocity at each time step and compute the new angle based on their values

(它看起来你有X和Y从传统的命名法切换,BTW(Y通常是受到重力的方向,但也许它是在你的情况下,屏幕坐标)。

(It looks like you have x and y switched from traditional nomenclature, btw (y is usually the direction affected by gravity, but perhaps it is a screen coordinate in your case).

yv = v0 * Math.cos(alpha); // yv isn't changing so you can compute it outside
                           // the loop that increments time

xv = v0 * Math.sin(alpha) - g*t

if (yv != 0) {
  beta = (float)Math.atan(xv/yv);
}
else
{
  beta = xv < 0 ? -Math.PI/2 : Math.PI/2
}

这篇关于旋转箭时,它的飞行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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