Distance between two canvas co-ordinates in javascript -


i'm acquainted basic math , know equations, when try implement them in canvas fail.

here's relevant code:

    function distance(one,two){     var a, b     if(one[0] > one[1]){         = one[1] - one[0]     }else{         = one[0] - one[1]     }     if(two[0] > two[1]){         b = two[1] - two[0]     }else{         b = two[0] - two[1]     }      var c = a^2 + b^2;     return math.sqrt(c); }  radius = distance([centerx,e.clientx], [centery,e.clienty]) context.fillcircle(centerx, centery, radius, "white"); 

here's code in action

as can see, circle far short , don't know why... when remove sqrt, becomes out of whack quickly.

^ not think does.

js> 8^2 10 js> math.pow(8,2) 64 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -