From 5264bb1a9d14866b3a59fc88191d05d18f2e2524 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 6 Aug 2012 08:14:03 +0200 Subject: [PATCH] Add dot_product function for vector calculations and such --- core.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core.js b/core.js index 1373e8a..a08eb00 100644 --- a/core.js +++ b/core.js @@ -178,7 +178,7 @@ Function.prototype.inheritsFrom = function(parentObject) this.Add = function() { var new_point = new RadiumEngine.Point(this.x, this.y); - console.log(arguments); + for (i in arguments) { new_point.x += arguments[i].x; @@ -208,4 +208,17 @@ Function.prototype.inheritsFrom = function(parentObject) var yL = y1 - y2; 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; + } }