Skip to content

Instantly share code, notes, and snippets.

@isedgar
Created July 2, 2021 03:17
Show Gist options
  • Save isedgar/6da4795f182f54a74411c3009b36f351 to your computer and use it in GitHub Desktop.
Save isedgar/6da4795f182f54a74411c3009b36f351 to your computer and use it in GitHub Desktop.
Get the inner angle at point "b" in degrees
function inner_angle(a,b,c){ // inner angle at point b in degrees
var v1=[a[0] - b[0], a[1] - b[1]],
v2=[c[0] - b[0], c[1] - b[1]];
return Math.acos(math.inner(v1, v2) / (math.norm(v1) * math.norm(v2))) * 180 / Math.PI;
}
var math={
norm: function(v){
var s=0, n=v.length;
for(var i=0; i < n; ++i){
s += Math.pow(v[i], 2);
}
return Math.sqrt(s);
},
inner: function(a,b){
var s=0;
for(var i=0; i < a.length; ++i){
s += (a[i]*b[i]);
}
return s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment