• Create Account

## Mad approach for collision detection

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Hotwire  Members

Posted 06 May 2014 - 10:07 AM

Hello

Problem:

I have a surface which is given by eq. F(x_i)==0 and I have a point y. And I want to know if it is inside or outside.

2D case.
Let's move to complex plane first. Create a function f which has a single pole right at point y

f(z)=1/(z-y)

Then evaluate the integral

\int_\gamma f(z) dz

along the curve \gamma that is given by eq. F(x_i)==0.

Because I know the answers for both cases(outside and inside), just looking at the sign I'll solve my problem. It works for both convex and noncovex curves

3D case
We make a 2d slice. Then make the same procedure. For convex surfaces it will be enough to use just one slice, for nonconvex surfaces...
it's a real mess but seems to be possible(from just mathematical point of view). One slice is still enough but we can have much more contours then one.

What do you think about that?

p.s. It was my childhood dream to create my own physics engine, now I am theretical physicist but i still want to )))

Posted 07 May 2014 - 01:21 AM

Have you tried it in real code yet?

You would probably want to avoid heavy use od divisions because they're very costly in terms of cpu cycles.

I don't know if this approach works for games though...

### #3samoth  Members

Posted 07 May 2014 - 05:39 AM

I don't think that anything with "evaluate the integral" in it has a realistic chance of working as a collision system (unless the curve is a particular special case for which you can hardcode an easy closed form solution).

Usually you want something that works realtime or at least kind-of-realtime, and the algorithm is invoked for a few hundred or thousand objects. Evaluating a few thousand integrals of "some" function isn't precisely a lightweight operation. Of course, there may be cases where you simply don't care how long it takes...

### #4Hotwire  Members

Posted 07 May 2014 - 06:44 AM

I have a figure which is given by array of triangles and I have couple of points that i know for sure that they are inside my figure and I have my testing point. I build a plane with these three points.

Now I need to extract the curve that was created by the slice.
First of all I need to seperate the triangles that really contribute to curve. if all three points are on the one side they don't contribute

I'll switch the coordinate system and check if z coordinates for all point are greater then zero or less. (one dot product+sum per vertex)

If triange intersects the plane I can easily find the solution to this intersection.(at least 4 dot products for one triangle)

My curve is a polygon. It is not hard to integrate along this curve.

One can easily see that during the separation (for convex figures) I will make 3 times more operations that one may need for the answer. But probably it's a reasonable price to pay to collide non-convex polygons

### #5Bacterius  Members

Posted 07 May 2014 - 08:27 AM

You can use LaTeX here. Just enclose your code in \ ( and \ ) (without the spaces) for inline math, and \ [ and \ ] for display math. For instance $$\int_0^\infty e^x ~ \mathrm{d} x$$.

Seems to me that you don't really need to compute the full path integral, since you only require its sign. You can do much better. If your curve/surface is closed and bounded you can use the even-odd theorem, which basically says that if you draw a ray from your point to infinity in any direction, the point is inside the curve if and only if it intersects the curve an odd number of times. This rule works for any (nondegenerate) curve or surface, convex or not. Note this is an if and only if condition, so one ray is enough to decide (and, in fact, it is transitive, in the sense that if the segment between point X and point Y has an even number of intersections, then X and Y are both inside or both outside). This is really just evaluating the sign of the aforementioned path integral, but much easier to implement because it doesn't require the concept of an integral and transforms the problem into a ray-surface intersection problem for which efficient solutions are known.

If your curve is simple, you can probably intersect it analytically with a line. If it is sufficiently well-behaved and you have a scalar field of it available, like in your first post, you can bisect to find intersections, which is at least tractable, if not terribly efficient. Otherwise, you can always raycast or raymarch, possibly using an acceleration structure. In practice, faster algorithms are used for the broad phase, while more sophisticated algorithms are used to resolve collisions accurately between polygons (narrow phase) often by splitting them into convex polygons beforehand.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.