从任意角度的墙壁弹起一个球? [英] Bouncing a ball off a wall with arbitrary angle?

查看:118
本文介绍了从任意角度的墙壁弹起一个球?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让用户画出一个桨,然后他们可以用它来击球.但是,我似乎无法使球正确反弹,因为球速度的x和y分量未与墙对齐.我该如何解决?

I'm trying to let the user draw a paddle that they can then use to hit a ball. However, I cannot seem to get the ball to bounce correctly because the x and y components of the ball's velocity are not lined up with the wall. How can I get around this?

我尝试了Gareth Rees的建议此处,但显然我没有对向量没有足够的了解,以便能够遵循它.例如,我不知道您在向量中到底存储了什么-我知道这是一个带有方向的值,但是您是否存储了它之间的2个点,即坡度,角度?

I tried the advice given by Gareth Rees here, but apparently I don't know enough about vectors to be able to follow it. For example, I don't know what exactly you store in a vector - I know it's a value with direction, but do you store the 2 points it's between, the slope, the angle?

我真正需要的是在击球时给定壁的角度以及x和y的速度,以便随后找到新的x和y的速度.

What I really need is given the angle of the wall and the x and y velocities as the ball hits, to find the new x and y velocities afterwards.

推荐答案

加里斯·里斯(Gareth Rees)给出了正确的公式,但我发现了图片和解释

Gareth Rees got the formula correct, but I find the pictures and explanation here a little more clear. That is, the basic formula is:

Vnew = -2*(V dot N)*N + V
where
V = Incoming Velocity Vector
N = The Normal Vector of the wall

由于您不熟悉向量符号,因此需要了解以下公式:向量基本上是x,y对,因此V = (v.x, v.y)N = (n.x, n.y).最好用垂直于平面的法线来描述平面,即垂直于平面的单位长度的向量.然后是几个公式,b*V = (b*v.x, b*v.y); V dot N = v.x*n.x+v.y*n.y,也就是说,它是一个标量;和A + B = (a.x+b.x, a.y+b.y).最后,要找到基于任意矢量的单位矢量,它是N = M/sqrt(M dot M).

Since you're not familiar with vector notation, here's what you need to know for this formula: Vectors are basically just x,y pairs, so V = (v.x, v.y) and N = (n.x, n.y). Planes are best described by the normal to the plane, that is a vector of unit length that is perpendicular to the plane. Then a few formula, b*V = (b*v.x, b*v.y); V dot N = v.x*n.x+v.y*n.y, that is, it's a scalar; and A + B = (a.x+b.x, a.y+b.y). Finally, to find a unit vector based on an arbitrary vector, it's N = M/sqrt(M dot M).

如果表面是弯曲的,则在接触点使用法线.

If the surface is curved, use the normal at the point of contact.

这篇关于从任意角度的墙壁弹起一个球?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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