请帮我算一个三角函数
这是问题的图形表示: http://i.imgur.com/aBG3p.jpg
给定一个起点 (x1,y1 )和目标点(x2,y2),我必须确定两点之间的路径是否开放,或者如果不开放,则碰撞发生在哪个坐标上。
除了所涉及的特殊规则之外,这将是一个微不足道的问题:
线可以截取一个点,在较小且不同的程度上将其称为(i,j),而不会引起碰撞。如果 (i,j) 与 (x1,y1) 直接相邻,我们可以安全地在其角上切割大约 0.4,而不会触发碰撞。然而,如果直接穿过它,我们就不能削减 0.4,只能跨越拐角。当我们远离 (x,y) 时,这个数字逐渐减小到大约 0.2。不幸的是,我只是试图重建我曾经见过的东西,所以我不知道确切的值,我只是近似它们。
对 1 的警告:如果在我们相交的平面中,在我们相交的一侧,紧邻 (i,j) 的空间也被占据,那么无论如何都会发生碰撞。如果我们拦截太多,就会发生碰撞 (i,j),否则在相关的相邻图块中。
我已经多次尝试解决这个问题,但总是以漏报和/或在错误的图块上产生碰撞而告终。我尝试在不考虑角度的情况下完成此操作,只需在沿线行进时查看 x 和 y 的小数点即可。我不确定是否可以做到这一点,或者我是否必须以某种方式使用角度,或者以某种方式使用角度是否可以让我的生活更轻松。
如果可以的话请帮忙!
Here is a graphic representation of the problem:
http://i.imgur.com/aBG3p.jpg
Given a starting point (x1,y1) and a destination point (x2,y2), I must determine if the path between the two points is open or, if it is not open, which coordinate the collision happens on.
It would be a trivial problem except for the special rules involved:
The line can intercept a point, call it (i,j) to a small and varying degree without causing a collision. If (i,j) is directly adjacent to (x1,y1), we can safely cut about 0.4 over its corners without triggering a collision. However we cannot cut 0.4 over if going directly through it, only over the corners. This number tapers off to about 0.2 as we get further away from (x,y). Unfortunately I'm just trying to reconstruct something I saw once, so I don't know the exact values, I'm just approximating them.
The caveat to 1: If the space directly beside (i,j), in the plane that we are intersecting, on the side that we are intersecting, is also occupied, there will be a collision no matter what. The collision will happen (i,j) if we intercept it by too much, otherwise in the relevant adjacent tile.
I've made several tries to crack this problem, always ending up with false negatives and/or the collision resulting on the wrong tile. I tried to do it without considering the angle, just by looking at the decimal points of x and y as we travel down the line. I'm not sure if it is possible to do this, or if I must use the angle in some way, or if using the angle in some way could make my life easier.
Please help if you can!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将占用的网格视为包含单位圆,您似乎可以获得与您描述的结果类似的结果。这会让你通过拐角,但会阻挡任何两个相邻的拐角,因为它们接触。
因此,我会尝试使用当前的碰撞方法快速检查矩形,然后在发现碰撞后通过测试进入框的线与以框为中心的圆来对其进行细化。
It seems like you could get results similar to what you describe by treating the occupied grids as containing unit circles. That would let you pass corners, but block on any 2 adjacent ones, since they contact.
So I'd try using your current collision method to check rectangles quickly, then refining it once you found a collision, by testing the line entering the box against a circle centered in it.