add vector angle
This commit is contained in:
parent
7e851756de
commit
b5e655e1f2
|
@ -1494,6 +1494,16 @@ Vector.random = function() {
|
||||||
return Vector.norm(vec);
|
return Vector.norm(vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector.angle_between = function(a,b)
|
||||||
|
{
|
||||||
|
var dot = Vector.dot(a,b);
|
||||||
|
var am = Vector.length(a);
|
||||||
|
var bm = Vector.length(b);
|
||||||
|
var cos_a = dot / (am*bm);
|
||||||
|
var angle = Math.acos(cos_a);
|
||||||
|
return Math.rad2turn(angle);
|
||||||
|
}
|
||||||
|
|
||||||
Vector.angle = function(v) { return Math.rad2turn(Math.atan2(v.y, v.x)); }
|
Vector.angle = function(v) { return Math.rad2turn(Math.atan2(v.y, v.x)); }
|
||||||
Vector.rotate = function(v,angle) {
|
Vector.rotate = function(v,angle) {
|
||||||
var r = Vector.length(v);
|
var r = Vector.length(v);
|
||||||
|
|
Loading…
Reference in a new issue