Add dot_product function for vector calculations and such

master
Sven Slootweg 12 years ago
parent f6c0760798
commit 5264bb1a9d

@ -178,7 +178,7 @@ Function.prototype.inheritsFrom = function(parentObject)
this.Add = function() this.Add = function()
{ {
var new_point = new RadiumEngine.Point(this.x, this.y); var new_point = new RadiumEngine.Point(this.x, this.y);
console.log(arguments);
for (i in arguments) for (i in arguments)
{ {
new_point.x += arguments[i].x; new_point.x += arguments[i].x;
@ -208,4 +208,17 @@ Function.prototype.inheritsFrom = function(parentObject)
var yL = y1 - y2; var yL = y1 - y2;
return Math.sqrt((xL * xL) + (yL * yL)); return Math.sqrt((xL * xL) + (yL * yL));
} }
RadiumEngine.dot_product = function(a, b)
{
var n = 0;
var lim = Math.min(a.length, b.length);
for (var i = 0; i < lim; i++)
{
n += a[i] * b[i];
}
return n;
}
} }

Loading…
Cancel
Save