简体   繁体   English

如何计算撞墙的球的反射角

[英]How to calculate reflection angle of a ball colliding with a wall

I have a ball and I'm moving it toward an angle like this: 我有一个球,并且正朝着这样的角度移动它:

ball.x += ball.speed * Math.sin(ball.angle)
ball.y += ball.speed * -Math.cos(ball.angle)

How can I calculate the reflection angle when the ball collides with a wall?(horizontal or vertical) 球与墙碰撞时如何计算反射角?(水平或垂直)

Something like this 这样

For any wall with normal vector e_n a ball with initial velocity vector v_i has the velocity vector v_f after reflection with 对于具有法向矢量e_n的任何墙,具有初始速度矢量v_i的球在反射后具有以下速度矢量v_f

v_f = v_i - 2 dot( v_i, e_n) e_n , v_f = v_i - 2 dot( v_i, e_n) e_n

where dot is the vector dot-product. 其中dot是矢量点积。

Explanation: The projection of v_i on e_n is dot( v_i, e_n ) . 说明: v_ie_n上的投影为dot( v_i, e_n ) This is the velocity towards the wall and this is the part that gets reversed upon reflection. 这是朝向墙壁的速度,这是反射时反转的部分。 The component p = dot( v_i, e_n ) results in a vector p e_n . 分量p = dot( v_i, e_n )得出向量p e_n The remaining component can be calculated via a cross product or simply v_s = v_i - p e_n . 剩余分量可以通过叉积或简单地通过v_s = v_i - p e_n The final velocity is the non altered component plus the reversed projected component, ie v_s - p e_n = v_i - 2 p e_n = v_i - 2 dot( v_i, e_n) e_n 最终速度是v_s - p e_n = v_i - 2 p e_n = v_i - 2 dot( v_i, e_n) e_n分量加上反向投影分量,即v_s - p e_n = v_i - 2 p e_n = v_i - 2 dot( v_i, e_n) e_n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM