I want to create Geometry Objects Like Points & Vectors But I preferred if can calculate its using Mathematical operators like (+,-,*)
see this code
below :
var Point = function(px,py,pz){return {x:px,y:py,z:pz,class:'point'}};
var Vector = function(p,d){
//p is origin point of vector
//d can be other Point or distance(not use it here)
var V = {};
if(d.class=='point'){
V.class = 'vector';
V.origin = p;
V.x = d.x-p.x,
V.y = d.y-p.y;
V.z = d.z-p.z;
V.magnitude = Math.sqrt(V.x*V.x+V.y*V.y+V.z*V.z);
//can be add here some other properties and Methods
//...
}else{/* some code not required */};
return V
};
// My question is if there way can be calculate two vectors using Mathematical Operators
var A = Point(2,4,1); // Point A
var B = Point(3,-2,5); // other Point B
var V1 = Vector(A,B); // 1st Vector
var V2 = Vector(A,Point(0,1,1)); // 2nd Vector
//now when add 1st Vector with 2nd Vector have a result new Vector like a Math
Va = V1 + V2 ; // i know i must add methods for calculate it
// but I'm ask if can put this Methods as Operator(+,*,^...)
if not : what is best way to use RegExp
to make it as above
and sorry if have a wrongs into...