FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Simulation, Artificial Life
(Moderator: REAS)
   Curved Surface Collisions
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Curved Surface Collisions  (Read 3239 times)
flight404

WWW Email
Curved Surface Collisions
« on: Jan 7th, 2005, 8:45pm »

I am working on a new project where an amorphous black shape has objects within it which use front and side feelers to move about the inside of the black shape.  If any of the feelers sees that it is no longer atop a black pixel, the object either slows down, or adjusts its direction of movement accordingly.
 
But this got me to thinking... how would one go about doing collision reactions based on a collision with a curved surface.
 
http://www.flight404.com/p5/image/curveCollision.gif
 
I was wondering if people could point me in the right direction for figuring out how this sort of thing is dealt with.  I had tried playing around with an object containing several front-facing feelers, and once the parent object determines that the next move will collide with the wall, check to see how long the feelers have been outside the boundary of the containing shape, and somehow use that information to determine the slope of the line at the point of collision...
 
But alas, that just doesn't seem like the easiest way to deal with this.
 
r
 
zach


Re: Curved Surface Collisions
« Reply #1 on: Jan 7th, 2005, 10:57pm »

hi,
 
I never got this working perfectly, but I did implement it at some point.  One strategy was line, line collision by extending the particle two time frames (x += vx; vx += ax;) forward.  the main problem is if the curved surface is animating, it's quite possible to over step and wind up on the other side of the surface.  My solution was a point in polygon test to see if I had made it on the other side, then a nearest point on line to get the particle back on the other side and to caluclate the bounce vector.
 
on the flip side, you could do it in the pixel domain using a vector field....
 
my main suggestion, though, is to try the forums on gamedev.net or other game development sites where you will find lots of posts on a variety of collision detection techniques.
 
- zach
 
Fish-face

308232952308232952thedemonsheep WWW Email
Re: Curved Surface Collisions
« Reply #2 on: Jan 20th, 2005, 5:33pm »

Hmm... You just need to find the normal of the point at which you're colliding, so if you have the equation of the curved surface, you can differentiate...
But with arbitrary curved surfaces, it might be more difficult, unless you can use your curve-making algorithm to give you an equation.
 

--

The C@ S@ on the M@
=Fish-Face=
~#Chris#~
zach


Re: Curved Surface Collisions
« Reply #3 on: Feb 6th, 2005, 4:27pm »

however in most cases, your curved surface can be approximated as a series of line segments, for which those calculation are trivial.
 
mflux

fluxhavoc WWW
Re: Curved Surface Collisions
« Reply #4 on: Feb 9th, 2005, 5:41am »

Hmm... I did this before a long time ago. Processing has a built in function to return a given curve so that you can find the normal.
 
http://classes.design.ucla.edu/Fall03/157A/cursos/00/index_visor.php?id= 8&ejercicio_id=9&persona_id=20
 
Click the lower right hand "number" button until you reach path following.
 
curvePoint() and bezierPoint() does the trick.  
 
My function just takes a series of points that created the bezier, another point, and finds the closest distance that point is to the curve. The method is pretty crude but for the most part it works.
 
position findClosestCP(position p[],position m)
{
//  position m=new position(mouseX,mouseY);
  position cp=new position(p[1]);
  float d=dist(cp,m);
  int seg;
  for(int s=0;s<p.length-3;s++)
  {
    for(float t=0;t<1;t+=.01)
    {
      if(dist(m.x,m.y,curvePoint(p[s].x,p[s+1].x,p[s+2].x,p[s+3].x,t),curvePoint(p[s+0].y,p[s+1].y,p[s+2].y,p[s+3].y,t))<d)
      {
        cp=new position(curvePoint(p[s].x,p[s+1].x,p[s+2].x,p[s+3].x,t),curvePoint(p[s+0].y,p[s+1].y,p[s+2].y,p[s+3].y,t));
        d=dist(m.x,m.y,curvePoint(p[s].x,p[s+1].x,p[s+2].x,p[s+3].x,t),curvePoint(p[s+0].y,p[s+1].y,p[s+2].y,p[s+3].y,t));
      }
    }
  }
  return cp;
}
 
 
Another place that uses curve intersection:
http://users.design.ucla.edu/~mflux/p5/particle_graph/applet/
 
Click generate after making a curve.
 
Good luck!
« Last Edit: Feb 9th, 2005, 5:41am by mflux »  
Pages: 1 

« Previous topic | Next topic »