0

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...

Tamsamani
  • 76
  • 1
  • 8
  • Regex has absolutely nothing to do with this and won't even help you to implement something similar. – Bergi Aug 31 '14 at 17:08
  • @Bergi I mean if I've previously Methods Like Vector1.add(Vectro2); can I use RegExp to eval String Like `"Vectro1 + Vector2"` – Tamsamani Aug 31 '14 at 17:11
  • No, you cannot use regex even for evaling string expressions, unless you limit yourself to non-infinitely nested expressions. – Bergi Aug 31 '14 at 17:15

0 Answers0