1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 /// \class AliMUONPolygon
20 /// A simple planar polygon, with a given orientation
22 /// \author Laurent Aphecetche, Subatech
24 #include "AliMUONPolygon.h"
27 #include "Riostream.h"
31 ClassImp(AliMUONPolygon)
34 //_____________________________________________________________________________
35 AliMUONPolygon::AliMUONPolygon(Int_t nvertices)
41 /// Ctor with a predefined number of vertices.
44 //_____________________________________________________________________________
45 AliMUONPolygon::AliMUONPolygon(Double_t xpos, Double_t ypos, Double_t halfsizex, Double_t halfsizey)
51 /// Ctor. Polygon will be a rectangle.
54 double xmin(xpos-halfsizex);
55 double xmax(xpos+halfsizex);
56 double ymin(ypos-halfsizey);
57 double ymax(ypos+halfsizey);
59 SetVertex(0,xmin,ymin);
60 SetVertex(1,xmax,ymin);
61 SetVertex(2,xmax,ymax);
62 SetVertex(3,xmin,ymax);
68 //_____________________________________________________________________________
69 AliMUONPolygon::~AliMUONPolygon()
76 //______________________________________________________________________________
77 AliMUONPolygon::AliMUONPolygon(const AliMUONPolygon& rhs)
87 fX = new Double_t[fN];
88 fY = new Double_t[fN];
90 for ( Int_t i = 0; i < fN; ++i )
100 //______________________________________________________________________________
102 AliMUONPolygon::operator=(const AliMUONPolygon& rhs)
104 /// Assignment operator
107 static_cast<TObject&>(*this)=rhs;
119 fX = new Double_t[fN];
120 fY = new Double_t[fN];
122 for ( Int_t i = 0; i < fN; ++i )
133 //______________________________________________________________________________
135 AliMUONPolygon::Contains(Double_t x, Double_t y) const
137 /// Whether the polygon contains point (x,y)
139 // Note that the polygon must be a closed polygon (1st and last point
140 // must be identical), which should be the case here.
142 return TMath::IsInside(x,y,fN,fX,fY);
145 //_____________________________________________________________________________
147 AliMUONPolygon::Close()
149 /// Make that last point = first point
151 SetVertex(fN-1,X(0),Y(0));
154 //_____________________________________________________________________________
155 void AliMUONPolygon::Print(Option_t*) const
158 cout << Form("AliMUONPolygon : %3d vertices. Signed Area=%e",NumberOfVertices(),SignedArea()) << endl;
159 for ( Int_t i = 0; i < NumberOfVertices(); ++i )
161 cout << Form("%10.5f,%10.5f",X(i),Y(i)) << endl;
165 //_____________________________________________________________________________
167 AliMUONPolygon::SignedArea() const
169 /// Compute the signed area of this polygon
170 /// Algorithm from F. Feito, J.C. Torres and A. Urena,
171 /// Comput. & Graphics, Vol. 19, pp. 595-600, 1995
175 for ( Int_t i = 0; i < NumberOfVertices()-1; ++i )
177 area += X(i)*Y(i+1) - X(i+1)*Y(i);
183 //_____________________________________________________________________________
185 AliMUONPolygon::ReverseOrientation()
187 /// Reverse the orientation of this polygon
188 Double_t* x = new Double_t[fN];
189 Double_t* y = new Double_t[fN];
191 for ( Int_t i = fN-1; i >= 0; --i )
204 //_____________________________________________________________________________
206 AliMUONPolygon::SetVertex(Int_t i, Double_t x, Double_t y)
211 AliFatal("Wrong index");