Advertisement
BlueMagma

Untitled

Apr 27th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function intersect(C, R, A, B) {
  2.     var marge = 0.1
  3.     var dist = function  (X, Y) {
  4.         return Math.sqrt(Math.pow(X.x - Y.x, 2) + Math.pow(X.y - Y.y, 2))
  5.     }
  6.  
  7.     var dichotomie = function (I, O) {
  8.         if (dist(I, C) - D < marge) { return I }
  9.         else if (dist(O, C) - D < marge) { return O }
  10.         else {
  11.             var M = {"x": (I.x + (O.x - I.x) / 2), "y": (I.y + (O.y - I.y) / 2)}
  12.             if (dist(M, C) < D) { return dichotomie(M, O) }
  13.             else { return dichotomie(I, M) }
  14.         }
  15.     }
  16.  
  17.     var A_Inside = dist(A, C) < R;
  18.     var B_Inside = dist(B, C) < R;
  19.     if (A_Inside && B_Inside) {
  20.         return [undefined, undefined];
  21.     }
  22.     else if (A_Inside) {
  23.         return [A, dichotomie(A, B)];
  24.     }
  25.     else if (B_Inside) {
  26.         return [B, dichotomie(B, A)];
  27.     }
  28.     else {
  29.         // TODO : both outside
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement