问题标签 [collision-detection]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
318 浏览

geocoding - avoiding geocode range collisions

I am in the process of extracting location entities ('Madison Square Garden', 'San Diego Zoo', etc.) from a large table of non-uniform location. I'm trying to avoid multiple entities in my new table. I don't have reliable street addresses, but am trying to extract addresses within a local range.

I am doing this by counting and matching across similar names within a geo range of 30km.

I am going through a geocoded cities table, and for each city creating a lat/long range and then extracting the location names within that range.

Using Madison Square Gardens as an example. The venue would be overlapped multiple times from different cities in the cities table. For instance, Manhattan, Newark, etc. would all likely overlap the NYC range and result in multiple entries for some properties in NYC.

I can't just set the range to a smaller area as I would be missing locations, or worse, ending up with more multiple entries as I don't often have good street/city/geocoded locations (though a 30km area seems to work pretty well).

I was hoping that geohashing would enable me to create a bounding box where I would be able to find the overlap, and avoid multiple entries, but that doesn't seem to be the case based on what I've found.

Ideally, I believe I am looking for a hash or some other value I can put into a cell, and store a unique location name/hash so mysql doesn't end up with multiple entries for a single location.

I don't have proper street address for each entry (though I do have some), so getting street level accuracy and not using a range doesn't really seem to be an option. I also don't have consistent city names, so I end up with NYC, New York, Manhattan, etc. etc. But my cities table is better, including New York, but not NYC.

_--------------EDITED-------------------- After taking another look at Geohash.org, I think I am on the right track, just missing a bit of granularity. If I take the first two characters of the hash, that is consistent within a range that is just too large. For instance, everything from victoria, bc to portland, or is all 'C2' for the first two characters. However, going to a 3 character solution, NYC starts with 'dr5' and so does Newark (which is good), but Hackensack is 'dr7'. Worse, Vanouver, bc. is 'C2b', but the suburb of Richmond bc is 'C28'.

0 投票
1 回答
1584 浏览

silverlight-3.0 - 我如何知道 Silverlight 3 中两个矩形是否发生碰撞?

我有一个程序,你不能把矩形放在一起。如何检查矩形是否碰撞?是否有某种功能,或者我必须自己制作?

0 投票
1 回答
101 浏览

actionscript-3 - 当我尝试访问类的公共函数时,为什么会出现错误?(动作脚本 3)

我目前正在为我的游戏构建伤害机制。两个类处理这个,“伤害”类和“碰撞”类。伤害类将自身的一个实例传递给碰撞类的“hurtCollision”方法,以便碰撞类可以检测玩家与伤害实例(显示对象)之间的碰撞。但是,当我尝试访问该功能时,出现此错误:

这是两个类:

碰撞类(你可以 ctrl f 来伤害碰撞):

{

}

伤害等级:

{ 导入 flash.display.MovieClip; 导入 flash.events.Event;导入碰撞;

}

编辑:让大家知道,e.hurtPlayer 只是控制玩家健康的文档类方法。

0 投票
7 回答
254 浏览

oop - OO设计和镜像/复制方法

我在 OO 设计中遇到问题,最终在 2 个不同的类中出现重复代码。这是发生了什么:

在这个例子中,我想检测游戏对象之间的碰撞。

我有一个基础 CollisionObject,它包含扩展基类的常用方法(例如 checkForCollisionWith)和 CollisionObjectBox、CollisionObjectCircle、CollisionObjectPolygon。

这部分设计看起来不错,但让我感到困扰的是:调用

将在 Circle 子类中执行圆形与框碰撞检查。相反,

将在 Box 子类中执行 box vs circle 碰撞检查。

这里的问题是 Circle vs Box 碰撞代码是重复的,因为它在 Box 和 Circle 类中。有没有办法避免这种情况,还是我以错误的方式处理这个问题?现在,我倾向于拥有一个包含所有重复代码的辅助类,并从 aCircle 和 aBox 对象中调用它以避免重复。不过,我很好奇是否有更优雅的 OO 解决方案。

0 投票
2 回答
2278 浏览

xna - 圆和线段之间的碰撞处理

我正在实现一个小游戏,并且无法让物理正常工作。在这个游戏中,有一个球(一个在帧之间移动的圆,并且可能会改变半径)和几个墙(线段也在帧之间变化和移动)。我可以正确地检测到碰撞,让球以正确的方向反弹是没有问题的。

如果球在一帧中与一条线相交,然后在下一帧中再次与它相交,从而导致双弹跳,就会出现困难。我可以将球沿线的法线向后移动,直到它处于有效位置,但这会在有问题的线沿其轴被击中时导致非常奇怪的行为(想象一个乒乓球掉在直立的牙签上,然后突然移到一边,使它在牙签的一侧……)。当球在给定帧中与多条线相交时也会出现一些问题(想象四条线一起形成一个矩形并且球与所述矩形的角相交)——它应该从哪个方向反弹?它应该向哪个方向转变?

我真的没有具体的问题,但我正在寻找提示或一些有用的教程。到目前为止,我设法找到的所有 2D 仅涵盖矩形交叉点。

如果有任何区别,我正在使用 XNA。

谢谢,
卡梅伦

0 投票
4 回答
232 浏览

math - 简单问题 - 速度和碰撞

好的,我正在制作太空模拟游戏,与大多数太空模拟游戏一样,当我的子弹到达它时,我需要计算出对手飞船的位置(3d 位置)。我如何根据子弹行进的速度和对手船的速度来计算这个?

0 投票
5 回答
10049 浏览

c# - 三角形 - 三角形相交测试

我想知道是否有一些教程或指南来理解和实现 3D 环境中的三角形-三角形相交测试。(我不需要知道交叉路口发生的确切位置,而只需知道发生了交叉路口)

我打算按照理论上的 pdf 来实现它,但我很困在

  1. 计算三角形 2 的平面方程。
  2. 如果三角形 1 的所有点都在同一侧,则拒绝为微不足道。
  3. 计算三角形 1 的平面方程。
  4. 如果三角形 2 的所有点都在同一侧,则拒绝为微不足道。
  5. 计算相交线并投影到最大轴上。
  6. 计算每个三角形的间隔。
  7. 相交区间。

本指南的第 5 点。我真的不知道在问什么(所有 5,6 和 7)。XD

由于我的数学知识不高(嗯,我知道大学的几门考试给了我(我是一个原始程序员 XD)),请尽量对我简单。:D (我试图在谷歌上搜索,但大多数链接指向一些 4-5 页的公式,我真的不想知道也不懂。)

谢谢您的帮助

0 投票
4 回答
1741 浏览

collision-detection - 如何预先计算台球(台球)游戏中的轨迹?

台球中的大多数碰撞检测算法都使用一种简单的方法,即增加球的位置,然后检查碰撞。当速度非常高时,这种方法效果不佳,因为我们可能会“跳过”碰撞。

我一直在寻找一种方法来预先计算台球比赛中球的轨迹。一旦知道了轨迹,我就可以为球设置动画,直到它们停止移动。而且我不必担心速度,因为碰撞是在数学上检测和解决的。

你知道有没有人这样做过?我不想重新发明轮子。谢谢你。

0 投票
4 回答
4480 浏览

math - Collision Detection between Accelerating Spheres

I am writing a physics engine/simulator which incorporates 3D space flight, planetary/stellar gravitation, ship thrust and relativistic effects. So far, it is going very well, however, one thing that I need help with is the math of the collision detection algorithm.

The iterative simulation of movement that I am using is basically as follows:

(Note: 3D Vectors are ALL CAPS.)

Where:

What I basically need to do is to find some efficient formula that derives from (EQ.2) above for two objects (obj1, obj2) and tell if they ever collide, and if so, at what time. I need the exact time both so that I can determine if it is in this particular time increment (because acceleration will be different at different time increments) and also so that I can locate the exact position (which I know how to do, given the time)

For this engine, I am modelling all objects as spheres, all this formula/algorithm needs to do is to figure out at what points:

where .Distance is a positive scalar value. (You can also square both sides if this is easier, to avoid the square root function implicit in the .Distance calculation).

(yes, I am aware of many, many other collision detection questions, however, their solutions all seem to be very particular to their engine and assumptions, and none appear to match my conditions: 3D, spheres, and acceleration applied within the simulation increments. Let me know if I am wrong.)


Some Clarifications:

1) It is not sufficient for me to check for Intersection of the two spheres before and after the time increment. In many cases their velocities and position changes will far exceed their radii.

2) RE: efficiency, I do not need help (at this point anyway) with respect to determine likely candidates for collisions, I think that I have that covered.


Another clarification, which seems to be coming up a lot:

3) My equation (EQ.2) of incremental movement is a quadratic equation that applies both Velocity and Acceleration:

In the physics engines that I have seen, (and certainly every game engine that I ever heard of) only linear equations of incremental movement that apply only Velocity:

This is why I cannot use the commonly published solutions for collision detection found on StackOverflow, on Wikipedia and all over the Web, such as finding the intersection/closest approach of two line segments. My simulation deals with variable accelerations that are fundamental to the results, so what I need is the intersection/closest approach of two parabolic segments.

0 投票
2 回答
3079 浏览

2d - 带角球的 2D 球碰撞

我正在尝试编写一个从固定的垂直和水平墙壁反弹的球的 2D 模拟。模拟与墙壁表面的碰撞非常简单——只需否定垂直墙壁的 X 速度或水平墙壁的 Y 速度。问题是球也可能与墙壁的角落发生碰撞,水平墙壁与垂直墙壁相遇。我已经想出了如何检测何时发生与角落的碰撞。我的问题是球应该如何对这种碰撞做出反应——也就是说,它的 X 和 Y 速度将如何变化。

以下是我已经知道或知道如何找到的列表:

  • 检测到碰撞时的帧中球中心的 X 和 Y 坐标
  • 球速度的 X 和 Y 分量
  • 角点的 X 和 Y 坐标
  • 球心与角球的夹角
  • 球在碰撞前行进的角度
  • 检测到碰撞时球与角重叠的量

我猜最好假装角落是一个无限小的圆,所以我可以将球与那个圆之间的碰撞视为球与在碰撞点与圆相切的墙发生碰撞. 在我看来,我需要做的就是旋转坐标系与这个假想的墙对齐,在这个系统下反转球速度的 X 分量,然后将坐标旋转回原来的系统。问题是我不知道如何编程。

顺便说一句,这是一个理想的模拟。我没有考虑摩擦或球的旋转之类的东西。我正在使用 Objective-C,但我真的只是想要一个通用算法或一些建议。