Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / Game Design & Programming / Surface normal of a circle (verlet) Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
arctwelve

January 20, 2005, 03:00 PM

This is probably an easy one. When I use line segments for my surfaces (in 2D) I precompute the surface normal. But what if I wanted to use circles as surfaces. The collision test betw a circle and particle is obvious, but how do I get the normal to use in my collision response. Below is my current code for line segment collision response. (thanks to John Schultz for his previous help)


  1.  
  2. for (i = 0; i < this.particles.length; i++) {
  3. p = this.particles[i];
  4.  
  5. for (j = 0; j < this.surfaces.length; j++) {
  6. s = this.surfaces[j];
  7.  
  8. if (s.testInequality(p.curr.x, p.curr.y)) {
  9.  
  10.   vel = p.curr.minusNew(p.prev);
  11.   sDotV = s.normal.dot(vel);
  12.  
  13.   if (sDotV < 0) {
  14.  
  15.     // compute momentum of particle perpendicular to normal
  16.     velProjection = vel.minusNew(s.normal.multNew(sDotV));
  17.     perpMomentum = velProjection.multNew(this.coeffDrag);
  18.  
  19.     // compute momentum of particle in direction of normal
  20.     normMomentum = s.normal.multNew(sDotV * this.coeffRest);
  21.     totalMomentum = normMomentum.plusNew(perpMomentum);
  22.  
  23.     // set new velocity w/ total momentum
  24.     newVel = vel.minusNew(totalMomentum);
  25.  
  26.     // project out of collision
  27.     mirrorPos = s.normal.dot(p.curr.minusNew(s.p1)) * this.coeffRest;
  28.     p.curr.minus(s.normal.multNew(mirrorPos));
  29.  
  30.     // apply new velocity
  31.     p.prev = p.curr.minusNew(newVel);
  32.   }
  33. }
  34. }
  35. }
  36.  

 
Moe

January 20, 2005, 03:38 PM

“The collision test betw a circle and particle is obvious,”

vNormal = normalize(vIntersection - vCircleCenter);

Is that what you mean?

 
arctwelve

January 20, 2005, 05:07 PM

What is vIntersection there? the point at which the particle intersects with the circle?

 
John Schultz

January 20, 2005, 06:20 PM


arctwelve wrote: What is vIntersection there? the point at which the particle intersects with the circle?


vIntersection is the particle's position when you detected it was inside the circle ('curr'). The surface position to project out to is:

surfacePos = circleCenter + surfaceNormal*circleRadius

At higher velocities, you may want to compute the intersection of the line segment (curr, old) with the circle.

http://astronomy.swin.edu.au/~pbourke/geometry/sphereline/
http://www.magic-software.com/IntersectionBody.html

 
 
arctwelve

January 20, 2005, 08:54 PM

Needless to say it worked perfectly. thanks again!!

 
This thread contains 6 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.