评估与墙壁碰撞后的刚体线速度和旋转速度
Evaluating rigid body linear and rotational velocities after collision with a wall
我有一个相对简单的案例,我已经花了很长时间,我正在尝试手动评估(不使用任何库)二维正方形的旋转速度和线性速度和撞墙后的球。
鉴于:
r - is either radius or side length of the square
X1 - is a vector of initial position for a given rigid body
V1 - is a vector representing initial velocity of a given rigid body
R1 - is an initial rotational velocity of a given rigid body
W1 and W2 - are vectors representing position of a wall ends
C - is a vector representing point of collision
X2 - is a vector representing position for a given rigid body at the moment of contact with the wall
V2 - is a vector representing resulting velocity of a given rigid body after contact
R2 - is a rotational velocity of a given rigid body after contact
我知道我可能缺少一些参数,例如质量、阻尼、摩擦或描述墙 material 的属性,但我将其留给回答问题的人,因为可能有不同的模型。
我正在写 Dev Ramtal 和 Adrian Dobre 合着的一本书 "Apress Physics for JavaScript Games Animation and Simulations With HTML5 Canvas",但是这个主题非常广泛、支离破碎和稀疏。所以很难得到一个简单明确的答案是如何解决这种冲突的。
我曾尝试为旋转圆盘与墙壁碰撞的情况编写一些伪代码。希望对您有所帮助:
# unit vector aligned with the wall
T = W2 - W1
T = T / norm(T)
# unit vector perpendicular to the wall, pointing towards the moving object and
# hence perpendicular to T
N = [- T[1], T[0]]
# initial position and velocity:
X1 = [X1[0], X1[1]]
V1 = [V1[0], V2[1]]
R1 = angular velocity, positive if counter-clock-wise, negative otherwise
t_start = start time of simulation
t_stop = end time of simulation
k = friction coefficient,
that determines how much angular momentum
is converted into linear momentum during collision
t_col = t_start + dot(N, W1 + r*N - X1) / dot(N, V1)
if t_col < t_stop{
V2 = V1 - 2*dot(v1, n)*n - k*r*R1*T
R2 = (1 - k)* R1
X_col = X1 + V1*(t_col - t_start)
X_stop = X_col + V2*(t_stop - t_col)
C = X_col - r*N
} else{
X_stop = X1 + V1*(t_stop - t_start)
}
这是一个python版本,我只是想确保没有太多错误...
import numpy as np
# unit vector aligned with the wall
W1 = np.array([ -1, 0])
W2 = np.array([10, 1])
T = W2 - W1
T = T / np.linalg.norm(T)
# unit vector perpendicular to the wall, pointing towards the moving object and
# hence perpendicular to T
N = np.array([- T[1], T[0]])
# initial position and velocity:
X1 = np.array([ 0, 5])
V1 = 0.3 * np.array([ 1, -2])
#angular velocity, positive if counter-clock-wise, negative otherwise
R1 = -1.2
t_start = 0 #start time of simulation
t_stop = 3 #end time of simulation
k = 0.7 #friction coefficient,
#that determines how much angular momentum
#is converted into linear momentum during collision
r = 0.5 # radius of the disc
# time of collision
t_col = t_start + np.dot(N, W1 + r*N - X1) / np.dot(N, V1)
t_start = 0 #start time of simulation
t_stop = 8 #end time of simulation
k = 0.7 #friction coefficient,
#that determines how much angular momentum
#is converted into linear momentum during collision
r = 0.5
t_col = t_start + np.dot(N, W1 + r*N - X1) / np.dot(N, V1)
if t_col < t_stop:
V2 = V1 - 2*np.dot(V1, N)*N - k*r*R1*T
R2 = (1 - k)* R1
X_col = X1 + V1*(t_col - t_start)
X_stop = X_col + V2*(t_stop - t_col)
C = X_col - r*N
else:
X_stop = X1 + V1*(t_stop - t_start)
我有一个相对简单的案例,我已经花了很长时间,我正在尝试手动评估(不使用任何库)二维正方形的旋转速度和线性速度和撞墙后的球。
鉴于:
r - is either radius or side length of the square
X1 - is a vector of initial position for a given rigid body
V1 - is a vector representing initial velocity of a given rigid body
R1 - is an initial rotational velocity of a given rigid body
W1 and W2 - are vectors representing position of a wall ends
C - is a vector representing point of collision
X2 - is a vector representing position for a given rigid body at the moment of contact with the wall
V2 - is a vector representing resulting velocity of a given rigid body after contact
R2 - is a rotational velocity of a given rigid body after contact
我知道我可能缺少一些参数,例如质量、阻尼、摩擦或描述墙 material 的属性,但我将其留给回答问题的人,因为可能有不同的模型。
我正在写 Dev Ramtal 和 Adrian Dobre 合着的一本书 "Apress Physics for JavaScript Games Animation and Simulations With HTML5 Canvas",但是这个主题非常广泛、支离破碎和稀疏。所以很难得到一个简单明确的答案是如何解决这种冲突的。
我曾尝试为旋转圆盘与墙壁碰撞的情况编写一些伪代码。希望对您有所帮助:
# unit vector aligned with the wall
T = W2 - W1
T = T / norm(T)
# unit vector perpendicular to the wall, pointing towards the moving object and
# hence perpendicular to T
N = [- T[1], T[0]]
# initial position and velocity:
X1 = [X1[0], X1[1]]
V1 = [V1[0], V2[1]]
R1 = angular velocity, positive if counter-clock-wise, negative otherwise
t_start = start time of simulation
t_stop = end time of simulation
k = friction coefficient,
that determines how much angular momentum
is converted into linear momentum during collision
t_col = t_start + dot(N, W1 + r*N - X1) / dot(N, V1)
if t_col < t_stop{
V2 = V1 - 2*dot(v1, n)*n - k*r*R1*T
R2 = (1 - k)* R1
X_col = X1 + V1*(t_col - t_start)
X_stop = X_col + V2*(t_stop - t_col)
C = X_col - r*N
} else{
X_stop = X1 + V1*(t_stop - t_start)
}
这是一个python版本,我只是想确保没有太多错误...
import numpy as np
# unit vector aligned with the wall
W1 = np.array([ -1, 0])
W2 = np.array([10, 1])
T = W2 - W1
T = T / np.linalg.norm(T)
# unit vector perpendicular to the wall, pointing towards the moving object and
# hence perpendicular to T
N = np.array([- T[1], T[0]])
# initial position and velocity:
X1 = np.array([ 0, 5])
V1 = 0.3 * np.array([ 1, -2])
#angular velocity, positive if counter-clock-wise, negative otherwise
R1 = -1.2
t_start = 0 #start time of simulation
t_stop = 3 #end time of simulation
k = 0.7 #friction coefficient,
#that determines how much angular momentum
#is converted into linear momentum during collision
r = 0.5 # radius of the disc
# time of collision
t_col = t_start + np.dot(N, W1 + r*N - X1) / np.dot(N, V1)
t_start = 0 #start time of simulation
t_stop = 8 #end time of simulation
k = 0.7 #friction coefficient,
#that determines how much angular momentum
#is converted into linear momentum during collision
r = 0.5
t_col = t_start + np.dot(N, W1 + r*N - X1) / np.dot(N, V1)
if t_col < t_stop:
V2 = V1 - 2*np.dot(V1, N)*N - k*r*R1*T
R2 = (1 - k)* R1
X_col = X1 + V1*(t_col - t_start)
X_stop = X_col + V2*(t_stop - t_col)
C = X_col - r*N
else:
X_stop = X1 + V1*(t_stop - t_start)