source: Sophya/trunk/SophyaLib/Samba/circle.cc@ 3853

Last change on this file since 3853 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 6.2 KB
Line 
1#include <math.h>
2#include "sopnamsp.h"
3#include "circle.h"
4//++
5// Class Circle
6//
7// include circle.h math.h
8//--
9//++
10//
11// Links Parents
12//
13// Geometry
14//
15//--
16//++
17// Titre Constructors
18//--
19//++
20Circle::Circle()
21//
22//--
23{
24 UnitVector temp;
25 SetCircle(temp,M_PI/2.);
26}
27//++
28Circle::Circle(double theta, double phi, double aperture)
29//
30//--
31{
32 UnitVector temp(theta,phi);
33 SetCircle(temp,aperture);
34}
35//++
36Circle::Circle(double x, double y, double z, double aperture)
37//
38//--
39{
40 UnitVector temp(x,y,z);
41 SetCircle(temp,aperture);
42}
43//++
44Circle::Circle(const Vector3d& v, double aperture)
45//
46//--
47{
48 UnitVector temp=v;
49 SetCircle(temp,aperture);
50}
51//++
52Circle::Circle(const Circle& c)
53//
54// copy constructor
55//--
56{
57 UnitVector temp= c.Omega();
58 SetCircle(temp,c._angouv);
59}
60//++
61// Titre Public Methods
62//--
63//++
64void Circle::SetCircle(const UnitVector& temp, double aperture)
65//
66//--
67{
68 _spinunitaxis= temp;
69
70 _angouv = aperture;
71 _cangouv= cos(_angouv);
72 _sangouv= sin(_angouv);
73
74 _spinaxis=_spinunitaxis*fabs(_cangouv);
75
76 _theta =_spinunitaxis.Theta();
77 _ctheta= cos(_theta);
78 _stheta= sin(_theta);
79
80 _phi =_spinunitaxis.Phi();
81 _cphi= cos(_phi);
82 _sphi= sin(_phi);
83
84 _x= _spinunitaxis.X();
85 _y= _spinunitaxis.Y();
86 _z= _spinunitaxis.Z();
87}
88//++
89void Circle::SetSpinAxis(double theta, double phi)
90//
91//--
92{
93 UnitVector temp(theta,phi);
94 SetCircle(temp,_angouv);
95}
96//++
97void Circle::SetSpinAxis(const Vector3d& u)
98//
99//--
100{
101 UnitVector temp=u;
102 SetCircle(temp,_angouv);
103}
104//++
105void Circle::SetSpinAxis(double x, double y, double z)
106//
107//--
108{
109 UnitVector temp(x,y,z);
110 SetCircle(temp,_angouv);
111}
112//++
113void Circle::SetApertureAngle(double aperture)
114//
115//--
116{
117 SetCircle(_spinunitaxis,aperture);
118}
119//++
120void Circle::SetApertureAngle(const Circle& c)
121//
122//--
123{
124 SetCircle(_spinunitaxis,c._angouv);
125}
126
127//++
128UnitVector Circle::ConvToSphere(double psi) const
129//
130// Return UnitVector corresponding to a given position donnee on the circle
131//--
132{
133 psi=mod(psi,pi2);
134 double xout, yout, zout;
135 double cosa=cos(_angouv);
136 double sina=sin(_angouv);
137 double cost=cos(_theta);
138 double sint=sin(_theta);
139 double cosphi=cos(_phi);
140 double sinphi=sin(_phi);
141 double cosp=cos(psi);
142 double sinp=sin(psi);
143 xout = cosa*sint*cosphi+sina*(sinphi*sinp-cost*cosphi*cosp);
144 yout = cosa*sint*sinphi-sina*(cosphi*sinp+cost*sinphi*cosp);
145 zout = cosa*cost+sina*sint*cosp;
146 return UnitVector(xout,yout,zout);
147}
148//++
149UnitVector Circle::TanOnCircle(double psi) const
150//
151// Return UnitVector corresponding to the tangent to the circle
152// at given position on the circle.
153//--
154{
155 psi=mod(psi,pi2);
156 double xout, yout, zout;
157 double cost=cos(_theta);
158 double sint=sin(_theta);
159 double cosphi=cos(_phi);
160 double sinphi=sin(_phi);
161 double cosp=cos(psi);
162 double sinp=sin(psi);
163 xout = cosp*sinphi+sinp*sint*cosphi;
164 yout = -cosp*cosphi+sinp*sint*sinphi;
165 zout = -sinp*cost;
166 return UnitVector(xout,yout,zout);
167}
168//++
169UnitVector Circle::EPhi(double psi) const
170//
171// Return the vector tangent to the sphere in the plane (xy)
172// at a given position on the circle.
173//--
174{
175 psi=mod(psi,pi2);
176 return ConvToSphere(psi).EPhi();
177}
178//++
179UnitVector Circle::ETheta(double psi) const
180//
181// Return the other tangent vector( orthogonal to EPhi)--
182// see previous method
183//--
184{
185 psi=mod(psi,pi2);
186 return ConvToSphere(psi).ETheta();
187}
188//++
189double Circle::SepAngleTanEPhi02PI(double psi) const
190//
191// Return separation angle in [0,2Pi] at a given position on the
192// circle and EPhi
193//--
194{
195 psi=mod(psi,pi2);
196 UnitVector pol=this->TanOnCircle(psi);
197 UnitVector ephi=this->EPhi(psi);
198 double angle=pol.SepAngle(ephi);
199 if( pol.Z() <= 0 ) angle=pi2-angle;
200 return angle;
201}
202//++
203void Circle::Print(ostream& os) const
204//
205//--
206{
207 os << "1 - Circle - Axe de Spin Unitaire : " << _spinunitaxis << endl;
208 os << "1 - Circle - Axe de Spin : " << _spinaxis << endl;
209 os << "2 - Circle - Angle d'ouverture : " << _angouv << endl;
210 os << "3 - Circle - Theta,Phi : " << _theta << "," << _phi << endl;
211 os << "4 - Circle - x,y,z : " << _x << "," << _y << "," << _z << endl;
212}
213//++
214//
215// inline double Theta() const
216// inline double Phi() const
217// inline double ApertureAngle() const
218// inline Vector3d Omega() const
219//--
220//++
221// Titre Operators
222//--
223
224Circle& Circle::operator=(const Circle& c)
225{
226 if( this != &c )
227 {
228 UnitVector temp(c.Omega());
229 SetCircle(temp,c.ApertureAngle());
230 }
231 return *this;
232}
233//++
234bool Circle::operator==(const Circle& c) const
235//
236//--
237{
238 bool flag;
239 if( this == &c ) flag=true;
240 else flag=false;
241 return flag;
242}
243//++
244bool Circle::operator!=(const Circle& c) const
245//
246//--
247{
248 return (bool)(1-(this->operator==(c)));
249}
250//
251bool Circle::Intersection(const Circle& c) const
252{
253 double alphak= _angouv;
254 double alphal= c._angouv;
255 Vector3d ok= _spinaxis;
256 Vector3d ol= c._spinaxis;
257 double gamma= ok.SepAngle(ol);
258
259 if(fabs(alphak-alphal) < gamma && gamma <= (alphak+alphal) && this != &c) {
260 return true;
261 } else {
262 return false;
263 }
264}
265//
266bool Circle::Intersection(const Circle& c, double* psi) const
267{
268 double alphak= _angouv;
269 double alphal= c._angouv;
270 Vector3d ok= _spinaxis;
271 Vector3d ol= c._spinaxis;
272 double gamma= ok.SepAngle(ol);
273
274 if(fabs(alphak-alphal) < gamma && gamma <= (alphak+alphal) && this != &c) {
275
276 double sgamma= sin(gamma);
277 double cgamma= cos(gamma);
278
279 double sdphi= _sphi*c._cphi - _cphi*c._sphi;
280 double cdphi= _cphi*c._cphi + _sphi*c._sphi;
281
282 double ssk= c._stheta*sdphi/sgamma;
283 double csk= (c._ctheta*_stheta-c._stheta*_ctheta*cdphi)/sgamma;
284
285 double ssl= -_stheta*sdphi/sgamma;
286 double csl= (_ctheta*c._stheta-_stheta*c._ctheta*cdphi)/sgamma;
287
288 double ak= atan2(ssk,csk);
289 double al= atan2(ssl,csl);
290 double omegak= acos((c._cangouv-_cangouv*cgamma)/sgamma/_sangouv);
291 double omegal= acos((_cangouv-c._cangouv*cgamma)/sgamma/c._sangouv);
292
293 psi[0]= fmod(ak-omegak+pi2,pi2);
294 psi[1]= fmod(ak+omegak+pi2,pi2);
295 psi[2]= fmod(al-omegal+pi2,pi2);
296 psi[3]= fmod(al+omegal+pi2,pi2);
297
298 if(psi[0] > psi[1]) {
299 swap(psi[0],psi[1]);
300 swap(psi[2],psi[3]);
301 }
302 return true;
303
304 } else {
305 psi[0] = -1.;
306 psi[1] = -1.;
307 psi[2] = -1.;
308 psi[3] = -1.;
309 return false;
310 }
311}
Note: See TracBrowser for help on using the repository browser.