Changeset 8178 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 10/30/06 12:46:13 (18 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MMath.cc
r8073 r8178 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.30 2006-10-30 12:46:12 tbretz Exp $ 3 ! -------------------------------------------------------------------------- 2 4 ! 3 5 ! * … … 32 34 #include "MMath.h" 33 35 36 #ifndef ROOT_TVector2 37 #include <TVector2.h> 38 #endif 39 34 40 #ifndef ROOT_TVector3 35 41 #include <TVector3.h> … … 505 511 // -------------------------------------------------------------------------- 506 512 // 513 // Calculate the intersection of two lines defined by (x1;y1) and (x2;x2) 514 // Returns the intersection point. 515 // 516 // It is assumed that the lines intersect. If there is no intersection 517 // TVector2() is returned (which is not destinguishable from 518 // TVector2(0,0) if the intersection is at the coordinate source) 519 // 520 // Formula from: http://mathworld.wolfram.com/Line-LineIntersection.html 521 // 522 TVector2 MMath::GetIntersectionPoint(const TVector2 &x1, const TVector2 &y1, const TVector2 &x2, const TVector2 &y2) 523 { 524 TMatrix d(2,2); 525 d[0][0] = x1.X()-y1.X(); 526 d[0][1] = x2.X()-y2.X(); 527 d[1][0] = x1.Y()-y1.Y(); 528 d[1][1] = x2.Y()-y2.Y(); 529 530 const Double_t denom = d.Determinant(); 531 if (denom==0) 532 return TVector2(); 533 534 TMatrix l1(2,2); 535 TMatrix l2(2,2); 536 537 l1[0][0] = x1.X(); 538 l1[0][1] = y1.X(); 539 l2[0][0] = x2.X(); 540 l2[0][1] = y2.X(); 541 542 l1[1][0] = x1.Y(); 543 l1[1][1] = y1.Y(); 544 l2[1][0] = x2.Y(); 545 l2[1][1] = y2.Y(); 546 547 TMatrix a(2,2); 548 a[0][0] = l1.Determinant(); 549 a[0][1] = l2.Determinant(); 550 a[1][0] = x1.X()-y1.X(); 551 a[1][1] = x2.X()-y2.X(); 552 553 const Double_t X = a.Determinant()/denom; 554 555 a[1][0] = x1.Y()-y1.Y(); 556 a[1][1] = x2.Y()-y2.Y(); 557 558 const Double_t Y = a.Determinant()/denom; 559 560 return TVector2(X, Y); 561 } 562 563 // -------------------------------------------------------------------------- 564 // 507 565 // Solves: x^2 + ax + b = 0; 508 566 // Return number of solutions returned as x1, x2 -
trunk/MagicSoft/Mars/mbase/MMath.h
r7999 r8178 6 6 #endif 7 7 8 class TVector2; 8 9 class TVector3; 9 10 class TArrayD; … … 47 48 Double_t InterpolParabCos(const TVector3 &vx, const TVector3 &vy, Double_t x); 48 49 50 TVector2 GetIntersectionPoint(const TVector2 &x1, const TVector2 &y1, const TVector2 &x2, const TVector2 &y2); 51 49 52 inline Int_t SolvePol1(Double_t c, Double_t d, Double_t &x1) 50 53 {
Note:
See TracChangeset
for help on using the changeset viewer.