【发布时间】:2015-07-19 07:38:39
【问题描述】:
我有一个多边形,里面是一个移动的球。 如果球碰到边界,它应该会反弹回来。
我目前的“解决方案”: 我将多边形分成几行并计算球何时击中移动线
所有变量:
a = length of a
b = length of b
c = length of c
ax = x position of A
ay = y position of A
bx = x position of B
by = y position of B
cx = x position of C
cy = y position of C
vax = speed of A on the x-axis
vay = speed of A on the y-axis
vbx = speed of B on the x-axis
vby = speed of B on the y-axis
vcx = speed of C on the x-axis
vcy = speed of C on the y-axis
h = height (equals r, because it collides when h is r)
r = radius
t = time (one time unit equals 1 frame. not relevant)
axc = x positon of A at the collision
ayc = y positon of A at the collision
bxc = x positon of B at the collision
byc = y positon of B at the collision
cxc = x positon of C at the collision
cyc = y positon of C at the collision
-
计算所有点的碰撞位置:
axc:=ax+vax*tayc:=ay+vay*tbxc:=bx+vbx*tbyc:=by+vby*tcyc:=cy+vcy*tcxc:=cx+vcx*t -
计算所有顶点的长度
a:=√((axc-cxc)^(2)+(ayc-cyc)^(2))b:=√((bxc-cxc)^(2)+(byc-cyc)^(2))c:=√((axc-bxc)^(2)+(ayc-byc)^(2)) -
计算h
h=((√(2*(a^(2)*b^(2)+b^(2)*a^(2)+c^(2)*a^(2))-(a^(4)+b^(4)+c^(4))))/(2*c)) -
求解 t
solve(h=((√(2*(a^(2)*b^(2)+b^(2)*a^(2)+c^(2)*a^(2))-(a^(4)+b^(4)+c^(4))))/(2*c)), t)
BUUUUUT:我的计算器 (Ti-Nspire CX CAS) 崩溃。而且 Microsoft 数学花费的时间太长(我现在正在计算...... 1 小时,但仍然没有......)
所以...帮助!
(不要质疑我的绘画技巧)
【问题讨论】:
-
一些提示:球本身可能沿直线移动;当球的中心与线之间的距离小于或等于球的半径时,球接触另一条线。
-
顺便说一句,我假设你的多边形是凸的?
-
(或者最初只是多边形旋转,而不是球移动?)
-
你需要简化。一种简化是:计算好像 C 是静止的,并且 A 和 B 相对于 C 移动。这使得 Cxc 和 Cyc 独立于 t。此外,以 C 为原点会稍微简化方程。请注意,这不会改变解决方案。我看到球实际上是一个点。您可以计算 AB 和 AC 何时成为并行(点积)而不是计算 h,我认为这应该更容易(尤其是因为不应该有四阶项)
-
@HannoBinder 不,多边形不是凸的
标签: java math polygon geometry