用发生向量计算失败向量

calculate with vector of incidence a vector of failure

我尝试为带有二维线的球的动画编写失败向量。 我有线的齐次坐标,球的坐标和速度。 同性发病时。线和球的坐标接近于零,我想要 运行 一种方法,让球以相同的入射角从边界反弹,就像相同的失败角一样。 它是如何计算的?

在我看来,我需要球弹跳线的正常 vec,并且必须计算球的 x、y 的新速度,但我正在努力.... 帮助会很棒。

让我们假设我们给出了以下内容:

P1 = (px1, py1) ... line point 1
P2 = (px2, py2) ... line point 2
P1h = (px1, py1, 1) ... homogenous coordinates of line point 1
P2h = (px2, py2, 1) ... homogenous coordinates of line point 2
lh = P1h x P2h      ... homogenous coordinates of line (computed with cross product)
v = (vx, vy) ... vector of ball movement
B1 = (bx1, by1)          ... ball position 1
B2 = (bx2, by2) = B1 + v ... ball position 2
B1h = (bx1, by1, 1) ... homogenous coordinates of ball position 1
B2h = (bx2, by2, 1) ... homogenous coordinates of ball position 2

然后我们可以通过比较以下标量积的符号来检测球是否越过线:

ball crossed line  <==>  sign(B1h*lh) != 0 and sign(B1h*lh) != sign(B2h*lh)

要镜像运动,您可以计算 B1B2 的镜像 B1mB2m,分别穿过直线。然后 B2m 是新的球位置,vm = B2m - B1m 是球运动的新(镜像)方向。

如何计算点P与直线l的镜像?让我们假设

P  = (px, py)       ... point to be mirrored
Ph = (px, py, 1)    ... homogenous coordinates of point to be mirrored

另请注意,(lh.x, lh.y) 是直线 l 的法向量。现在按照以下步骤计算 Pl 的镜像 Pm:

|nl| = sqrt(lh.x^2+lh.y^2) ... length of normal vector
lh0 = lh / |nl|            ... "normalized" homogenous line, i.e. HNF (Hesse normal form) of line
d = Ph*lh0                 ... signed distance of P to l
lhP0 = lh0 + (0,0,d)       ... HNF of line parallel to l running through Pm
mh0 = (lh0.y, -lh0.x, 0)   ... HNF of line perpendicular to l (parallel to line
                               through P and Pm)
md = mh0*Ph                ... signed distance of P to mh0
mhP0 = mh0 - (0,0,md)      ... HNF of line through P and Pm
Pmh = lhP0 x mhP0          ... homogenous coordinates of mirrored point Pm