Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Tradekan

Hey, new guy here... I know I can get the length and angle that one entity is from another, but is it possible to tell if there is an entity directly between the two?

Thanks,
TraDekan

1 decade ago by Joncom

Pretend for a moment that you draw a line between EntityA and EntityB.
Your question, I think, is how to tell if a third entity is touching that line.

Perhaps useful?

1 decade ago by vincentpiel

If C is in the middle of A and B then angle(A,C) + angle(B,C) = Pi.
So you have to evaluate if

( Angle(A,C) + angle(B,C) - Pi ) % (2*Pi) ) < threshold.

Another way of solving this :
compute the distance from C to AB.
During this process, you will know if the normal projection of C on AB is within AB or not : this is the first thing you want to check.
Then you check that the distance from C to AB is not too big.
So based on this post :
http://stackoverflow.com/a/6853926/856501


// returns wether (x,y) point is within ( (x1,y1); (x2,y2) ) segment
// and nearer than maxDistance.
function isWithin(x, y, x1, y1, x2, y2, maxDistance) {

  var A = x - x1;
  var B = y - y1;
  var C = x2 - x1;
  var D = y2 - y1;

  var dot = A * C + B * D;
  var len_sq = C * C + D * D;
  var param = dot / len_sq;

  if ( (param < 0) || (param >1) ) return false; 

  var xx, yy;

   xx = x1 + param * C;
   yy = y1 + param * D;

   return (sq(x-xx)+ sq(y-yy)) < sq(maxDistance);
}

function sq(x) {return x*x }

1 decade ago by Tradekan

Thanks!! Those help a lot.
Page 1 of 1
« first « previous next › last »