Posts Tagged ‘arc collision’

Looking for advice on arc/point collision detection

Posted by (twitter: @Eliot_L)
Saturday, April 21st, 2012 11:29 pm

I’d appreciate some advice on whether my collison system can be salvaged or if I need to rewrite it.
My game is using polar coordinates and I am defining sections of arcs like so for the level geometry:

Right now I wrote checks to see if a point at polar coordinate (r, theta) is inside the region between the greater and lesser arc that makes up a solid object, like so:

class Arc {
  //Not a true arc, more of a segment of one or a "Block Arc", but it's much easier to type.
  float startAngle;
  float stopAngle;
  float maxRadius;
  float minRadius;
  boolean collidesWith(PolarCoord point) {
    return !( startAngle > point.t ||
              stopAngle < point.t ||
              minRadius > point.r ||
              maxRadius < point.r );

(Full class is here.)

It appears my math doesn’t work out for arcs on certain intervals. Previously I had encountered issues with this code not working when a radian was less than 0 or greater than 2*pi, so I wrapped my radians between 0 and 2*pi which fixed it. But I need to define some arcs that start around, say, the radian equivalent of ~270 degrees and end at ~45 degrees, making the shape of the letter C and crossing the 0 degrees mark. This kind of arc breaks my collision check above.

So I’m thinking, I can either fix my math for the check somehow, or abandon this method completely. Unfortunately I can’t find many resources on how to do this type of collision check properly. I couldn’t even find what these arc segment shapes are actually called.

In addition, I’m seeing occasional tunneling issues and would like to switch to doing an arc segment + line segment test for continuous collision instead of just an arc/point test.

The alternative I thought of was to define my arcs based on a vector at the center and an angle, and use the dot product to the player to do my collison checks, similar to the FOV check described here.

But it will take time to do that and I’d rather salvage this code if possible. If anyone has any advice, please let me know.

[cache: storing page]