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"
33 ClassImp(AliMUONPolygon)
36 //_____________________________________________________________________________
37 AliMUONPolygon::AliMUONPolygon(Int_t nvertices)
43 /// Ctor with a predefined number of vertices.
46 //_____________________________________________________________________________
47 AliMUONPolygon::AliMUONPolygon(Double_t xpos, Double_t ypos, Double_t halfsizex, Double_t halfsizey)
53 /// Ctor. Polygon will be a rectangle.
56 double xmin(xpos-halfsizex);
57 double xmax(xpos+halfsizex);
58 double ymin(ypos-halfsizey);
59 double ymax(ypos+halfsizey);
61 SetVertex(0,xmin,ymin);
62 SetVertex(1,xmax,ymin);
63 SetVertex(2,xmax,ymax);
64 SetVertex(3,xmin,ymax);
70 //_____________________________________________________________________________
71 AliMUONPolygon::~AliMUONPolygon()
78 //______________________________________________________________________________
79 AliMUONPolygon::AliMUONPolygon(const AliMUONPolygon& rhs)
89 fX = new Double_t[fN];
90 fY = new Double_t[fN];
92 for ( Int_t i = 0; i < fN; ++i )
102 //______________________________________________________________________________
104 AliMUONPolygon::operator=(const AliMUONPolygon& rhs)
106 /// Assignment operator
109 static_cast<TObject&>(*this)=rhs;
121 fX = new Double_t[fN];
122 fY = new Double_t[fN];
124 for ( Int_t i = 0; i < fN; ++i )
135 //______________________________________________________________________________
137 AliMUONPolygon::Contains(Double_t x, Double_t y) const
139 /// Whether the polygon contains point (x,y)
141 // Note that the polygon must be a closed polygon (1st and last point
142 // must be identical), which should be the case here.
144 return TMath::IsInside(x,y,fN,fX,fY);
147 //_____________________________________________________________________________
149 AliMUONPolygon::Close()
151 /// Make that last point = first point
153 SetVertex(fN-1,X(0),Y(0));
156 //_____________________________________________________________________________
157 void AliMUONPolygon::Print(Option_t*) const
160 cout << Form("AliMUONPolygon : %3d vertices. Signed Area=%e",NumberOfVertices(),SignedArea()) << endl;
161 for ( Int_t i = 0; i < NumberOfVertices(); ++i )
163 cout << Form("%10.5f,%10.5f",X(i),Y(i)) << endl;
167 //_____________________________________________________________________________
169 AliMUONPolygon::SignedArea() const
171 /// Compute the signed area of this polygon
172 /// Algorithm from F. Feito, J.C. Torres and A. Urena,
173 /// Comput. & Graphics, Vol. 19, pp. 595-600, 1995
177 for ( Int_t i = 0; i < NumberOfVertices()-1; ++i )
179 area += X(i)*Y(i+1) - X(i+1)*Y(i);
185 //_____________________________________________________________________________
187 AliMUONPolygon::ReverseOrientation()
189 /// Reverse the orientation of this polygon
190 Double_t* x = new Double_t[fN];
191 Double_t* y = new Double_t[fN];
193 for ( Int_t i = fN-1; i >= 0; --i )
206 //_____________________________________________________________________________
208 AliMUONPolygon::SetVertex(Int_t i, Double_t x, Double_t y)
213 AliFatal("Wrong index");