Re: Physics vectors ( was Re: vector classes predefined?)

From: Chris Jillings (chris@owl.phy.queensu.ca)
Date: Thu Jul 23 1998 - 19:11:49 MEST


Hi all,
    I have a threevector class which needs one or two things fixed in its
"rootification"
    The class has been used here at Queen's for many years on PC and
unix-based systems. It allows for easy use in formulas that look more like
math than code.
     For example the test macro I have put together is

{
  printf("This simple macro tests the TThreeVec class in interpreter mode.\n");
  printf("The macro will test *some* of the vector operations supported.\n");

  printf("==========================================\n");
  printf("Created a TThreeVec (3,4,0). Is it's length 5?\n");
  TThreeVec v1(3,4,0);
  Float_t length_v1 = v1.norm();
  printf("The length of TThreeVec v1 is %f.\n",length_v1);
  v1.normalize();
  printf("v1 has now been normalized. It had better be (0.6,0.8,0).\n");
  printf("It is in fact ( %f , %f , %f )\n",v1[0],v1[1],v1[2]);
  printf("==========================================\n");
  printf("The inside cover of JD Jackson's Classical Electrodynamics has");
  printf(" 3 vector formulas.\nLet's try them out.\n");
  TThreeVec a(45,87,102);
  TThreeVec b(5,-1024,19);
  TThreeVec c(-19,7,5);
  TThreeVec d(-123,-654,3.1E5);
  printf("a = (%f,%f,%f)\n",a[0],a[1],a[2]);
  printf("b = (%f,%f,%f)\n",b[0],b[1],b[2]);
  printf("c = (%f,%f,%f)\n",c[0],c[1],c[2]);
  printf("d = (%f,%f,%f)\n",d[0],d[1],d[2]);

  printf("a dot (b cross c) ?= b dot (c cross a) ?= c dot (a cross b)\n");
  Float_t first = a.dot(b.cross(c));
  Float_t second = b.dot(c.cross(a));
  Float_t third = c.dot(a.cross(b));
  printf("  %f  ?=  %f  ?=  %f \n",first,second,third);
    
  printf("==========================================\n");
  printf(" a cross (b cross c) ?= (a dot c)b - (a dot b)c \n");
  TThreeVec lhs = a.cross(b.cross(c));
  // Checking for commutation in scaler muliplication
  // The  line for rhs1 works. The line for rhs2 doesn't. Will fix before
  // issuing code.
  TThreeVec rhs1 = b*(a.dot(c)); // vector times scalar works.
  TThreeVec rhs2 = (a.dot(b))*c; // scalar times vector fails.
  TThreeVec rhs = rhs1 - rhs2;
  printf("(%f , %f , %f)  ?= (%f , %f , %f)\n",lhs[0],lhs[1],lhs[2],rhs[0],rhs[1],rhs[2]);

  printf("==========================================\n");
  printf("(a cross b) dot (c cross d) ?= (a dot c)(b dot d) - (a dot d)(b dot c)\n");
  first = (a.cross(b)).dot(c.cross(d));
  second = (a.dot(c)) * (b*d) -  (a*d) * (b.dot(c));
  printf("%f   &=  %f\n",first,second);

  printf("==========================================\n");
  printf("Test macro done.\n");

}

There are many shortcuts in the class. Vectors can be comraed with >, <;
they can be compared to Float_ts with <, >, ==. (It is there lengths in
both cases being compared.

It is a very nice class, which I can say because I didn't write it. I am
just taking on its rootification.

I will get the friend operators working next week and ship it to Fons for
testing and integration into root.

Chris


=================================================================
=                                                               =
= Chris Jillings                                                =
= Department of Physics   phone/voice mail: (613) 545-6000x4805 =   
= Queen's University      fax: (613) 545-6813                   =
= Kingston, Ontario       email: chris@sno.phy.queensu.ca       =             
= Canada, K7L 3N6         web: http://sno.phy.queensu.ca        =
=                                                               =
=================================================================



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET