Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function intersect(C, R, A, B) {
- var marge = 0.1
- var dist = function (X, Y) {
- return Math.sqrt(Math.pow(X.x - Y.x, 2) + Math.pow(X.y - Y.y, 2))
- }
- var dichotomie = function (I, O) {
- if (dist(I, C) - D < marge) { return I }
- else if (dist(O, C) - D < marge) { return O }
- else {
- var M = {"x": (I.x + (O.x - I.x) / 2), "y": (I.y + (O.y - I.y) / 2)}
- if (dist(M, C) < D) { return dichotomie(M, O) }
- else { return dichotomie(I, M) }
- }
- }
- var A_Inside = dist(A, C) < R;
- var B_Inside = dist(B, C) < R;
- if (A_Inside && B_Inside) {
- return [undefined, undefined];
- }
- else if (A_Inside) {
- return [A, dichotomie(A, B)];
- }
- else if (B_Inside) {
- return [B, dichotomie(B, A)];
- }
- else {
- // TODO : both outside
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement