A small vector class for Javascript June 7th, 2009

I have created a small class for handling 3D vectors. It could come in handy if you ever have to do some physics or graphics on a website.

Example:

// Create two vectors
var vec1 = new Vector(1.0, 1.0, 2.0);
var vec2 = new Vector(4.0, 2.3, 5.0);

// Calculate the dot product of the vectors
var scalar1 = vec1.Dot(vec2);
console.log(scalar1); // -->16.3

// Scale vec1 by scalar1
vec1 = vec1.Scale(scalar1);
console.log(vec1); // --> x: 16.3, y:16.3, z:32.6

// Cross product of vec2 and vec1
vec3 = vec2.Cross(vec1);
console.log(vec3); // --> x: -6.519 y: -48.90 z: 27.71

// Get the L2 norm of vec3:
scalar2 = vec3.Norm();
console.log(scalar2); // --> 56.582

// Return vec3 in Spherical coordinates:
sph3 = vec3.Spherical();
console.log(sph3); // --> phi: -1.70, r: 56.58, theta: 1.059

// Calculate ((vec1 + vec2) * vec3) * scalar1
vec4 = vec1.Add(vec2).Mult(vec3).Scale(scalar1);
console.log(vec4); // --> x: -2157.40, y: -14825.50, z: 16982.90

Download here:
Vector

Please post any comments or suggestions.

Wolfram|Alpha May 16th, 2009

Wolfram (the guy behind Mathematica) has launched a cute little Google killer running on multiple 40 TFLOP/s supercomputers. Think of it like an expert system on top of Mathematica with a nice database of every quantifiable piece of information out there (more or less)

I tried a very important question regarding a certain kind of bird just to see if it was in any way useful to my line of work:
Get answers to the really important questions in life!

Google Serverfarm May 15th, 2009

Mystery May 2nd, 2009

“Nothing is so dangerous to the progress of the human mind than to assume our views of science are ultimate, that there no mysteries in nature, that our triumphs are complete and that there are no new worlds to conquer”

Sir Humphry Davy