Is it possible to check the intersection of two circles faster than with the square squared algorithm?

I have this code to calculate the intersection of a circle thiswith a circle another. I want a faster version, is this possible?

this.CheckIntersection = function(another){
  var xC = this.x;
  var yC = this.y;
  var GxC = another.x;
  var GyC = another.y;
  var distSq = (xC - GxC) * (xC - GxC) + (yC - GyC) * (yC - GyC);
  return distSq < (this.r + another.r) * (this.r + another.r);
}
+4
source share
3 answers

Ok, you can improve this a bit:

this.CheckIntersection = function(another){
  var dx = this.x-another.x;
  var dy = this.y-another.y;
  dx = dx*dx+dy*dy;
  dy = this.r+another.r;
  return dx < dy*dy;
}

This will be a little faster, since you save some subtractions and use fewer variables so that the runtime has easier work with register allocation / caching.

. , , , .

+2

, GPU. GPU , , / . .

Nvidia cuda - , .

+1

, , , , , .

, . 3 +/2 * , 1 +/1 *. , , , , , , .

, , N , , N .

+1

Source: https://habr.com/ru/post/1623924/


All Articles