if(array1[j].x1 != array0[i].x1) { var a, b, sinus, cosinus, tangens, alpha; a = array1[j].y1 - array0[i].y2; b = array1[j].x1 - array0[i].x2; alpha = Math.atan(a/b); //alert(alpha); ctx.rotate(alpha); }