1 | #include <math.h>
|
---|
2 | #include "circle.h"
|
---|
3 |
|
---|
4 | Circle::Circle()
|
---|
5 | {
|
---|
6 | UnitVector temp;
|
---|
7 | SetCircle(temp,M_PI/2.);
|
---|
8 | }
|
---|
9 |
|
---|
10 | Circle::Circle(double theta, double phi, double aperture)
|
---|
11 | {
|
---|
12 | UnitVector temp(theta,phi);
|
---|
13 | SetCircle(temp,aperture);
|
---|
14 | }
|
---|
15 |
|
---|
16 | Circle::Circle(double x, double y, double z, double aperture)
|
---|
17 | {
|
---|
18 | UnitVector temp(x,y,z);
|
---|
19 | SetCircle(temp,aperture);
|
---|
20 | }
|
---|
21 |
|
---|
22 | Circle::Circle(const Vector3d& v, double aperture)
|
---|
23 | {
|
---|
24 | UnitVector temp=v;
|
---|
25 | SetCircle(temp,aperture);
|
---|
26 | }
|
---|
27 |
|
---|
28 | Circle::Circle(const Circle& c)
|
---|
29 | {
|
---|
30 | UnitVector temp=c.Omega();
|
---|
31 | SetCircle(temp,c._angouv);
|
---|
32 | }
|
---|
33 |
|
---|
34 | void Circle::SetCircle(const UnitVector& temp, double aperture)
|
---|
35 | {
|
---|
36 | _spinunitaxis=temp;
|
---|
37 | _angouv=aperture;
|
---|
38 | _spinaxis=_spinunitaxis*fabs(cos(_angouv));
|
---|
39 | _theta=_spinunitaxis.Theta();
|
---|
40 | _phi=_spinunitaxis.Phi();
|
---|
41 | _x=_spinunitaxis.X();
|
---|
42 | _y=_spinunitaxis.Y();
|
---|
43 | _z=_spinunitaxis.Z();
|
---|
44 | }
|
---|
45 |
|
---|
46 | void Circle::SetSpinAxis(double theta, double phi)
|
---|
47 | {
|
---|
48 | UnitVector temp(theta,phi);
|
---|
49 | SetCircle(temp,_angouv);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void Circle::SetSpinAxis(const Vector3d& u)
|
---|
53 | {
|
---|
54 | UnitVector temp=u;
|
---|
55 | SetCircle(temp,_angouv);
|
---|
56 | }
|
---|
57 |
|
---|
58 | void Circle::SetSpinAxis(double x, double y, double z)
|
---|
59 | {
|
---|
60 | UnitVector temp(x,y,z);
|
---|
61 | SetCircle(temp,_angouv);
|
---|
62 | }
|
---|
63 |
|
---|
64 | void Circle::SetApertureAngle(double aperture)
|
---|
65 | {
|
---|
66 | SetCircle(_spinunitaxis,aperture);
|
---|
67 | }
|
---|
68 |
|
---|
69 | void Circle::SetApertureAngle(const Circle& c)
|
---|
70 | {
|
---|
71 | SetCircle(_spinunitaxis,c._angouv);
|
---|
72 | }
|
---|
73 |
|
---|
74 | bool Circle::Intersection(const Circle& c, double* psi) const
|
---|
75 | {
|
---|
76 | double alphak=_angouv;
|
---|
77 | double alphal=c._angouv;
|
---|
78 | Vector3d ok=_spinaxis;
|
---|
79 | Vector3d ol=c._spinaxis;
|
---|
80 | double gamma=ok.SepAngle(ol);
|
---|
81 | if( fabs(alphak-alphal) < gamma && gamma <= (alphak+alphal) && this != &c )
|
---|
82 | {
|
---|
83 | // then the 2 circles intersect
|
---|
84 | double sg=sin(gamma),cg=cos(gamma);
|
---|
85 | double sak=sin(alphak),cak=cos(alphak);
|
---|
86 | double sal=sin(alphal),cal=cos(alphal);
|
---|
87 | double st=sin(_theta),ct=cos(_theta);
|
---|
88 | double stc=sin(c._theta),ctc=cos(c._theta);
|
---|
89 | double dphi=_phi-c._phi;
|
---|
90 | double sdphi=sin(dphi),cdphi=cos(dphi);
|
---|
91 | double sinusk=stc*sdphi/sg,cosinusk=(ctc*st-stc*ct*cdphi)/sg;
|
---|
92 | double sinusl=-st*sdphi/sg,cosinusl=(ct*stc-st*ctc*cdphi)/sg;
|
---|
93 | double gammaik=scangle(sinusk,cosinusk);
|
---|
94 | double gammail=scangle(sinusl,cosinusl);
|
---|
95 | double omegak=acos((cal-cak*cg)/sg/sak);
|
---|
96 | double omegal=acos((cak-cal*cg)/sg/sal);
|
---|
97 | psi[0]=fmod(gammaik-omegak+pi2,pi2);
|
---|
98 | psi[1]=fmod(gammaik+omegak+pi2,pi2);
|
---|
99 | psi[2]=fmod(gammail-omegal+pi2,pi2);
|
---|
100 | psi[3]=fmod(gammail+omegal+pi2,pi2);
|
---|
101 | if( psi[0] > psi[1] )
|
---|
102 | {
|
---|
103 | // psi[0]=psi(i,j,0)
|
---|
104 | // psi[1]=psi(i,j,1)
|
---|
105 | // psi[2]=psi(j,i,0)
|
---|
106 | // psi[3]=psi(j,i,1)
|
---|
107 | swap(psi[0],psi[1]);
|
---|
108 | swap(psi[2],psi[3]);
|
---|
109 | }
|
---|
110 | return true;
|
---|
111 | }
|
---|
112 | else
|
---|
113 | {
|
---|
114 | psi[0] = -1.;
|
---|
115 | psi[1] = -1.;
|
---|
116 | psi[2] = -1.;
|
---|
117 | psi[3] = -1.;
|
---|
118 | return false;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | UnitVector Circle::ConvToSphere(double psi) const
|
---|
123 | {
|
---|
124 | psi=mod(psi,pi2);
|
---|
125 | double xout, yout, zout;
|
---|
126 | double cosa=cos(_angouv);
|
---|
127 | double sina=sin(_angouv);
|
---|
128 | double cost=cos(_theta);
|
---|
129 | double sint=sin(_theta);
|
---|
130 | double cosphi=cos(_phi);
|
---|
131 | double sinphi=sin(_phi);
|
---|
132 | double cosp=cos(psi);
|
---|
133 | double sinp=sin(psi);
|
---|
134 | xout = cosa*sint*cosphi+sina*(sinphi*sinp-cost*cosphi*cosp);
|
---|
135 | yout = cosa*sint*sinphi-sina*(cosphi*sinp+cost*sinphi*cosp);
|
---|
136 | zout = cosa*cost+sina*sint*cosp;
|
---|
137 | return UnitVector(xout,yout,zout);
|
---|
138 | }
|
---|
139 |
|
---|
140 | UnitVector Circle::TanOnCircle(double psi) const
|
---|
141 | {
|
---|
142 | psi=mod(psi,pi2);
|
---|
143 | double xout, yout, zout;
|
---|
144 | double cost=cos(_theta);
|
---|
145 | double sint=sin(_theta);
|
---|
146 | double cosphi=cos(_phi);
|
---|
147 | double sinphi=sin(_phi);
|
---|
148 | double cosp=cos(psi);
|
---|
149 | double sinp=sin(psi);
|
---|
150 | xout = cosp*sinphi+sinp*sint*cosphi;
|
---|
151 | yout = -cosp*cosphi+sinp*sint*sinphi;
|
---|
152 | zout = -sinp*cost;
|
---|
153 | return UnitVector(xout,yout,zout);
|
---|
154 | }
|
---|
155 |
|
---|
156 | UnitVector Circle::EPhi(double psi) const
|
---|
157 | {
|
---|
158 | psi=mod(psi,pi2);
|
---|
159 | return ConvToSphere(psi).EPhi();
|
---|
160 | }
|
---|
161 |
|
---|
162 | UnitVector Circle::ETheta(double psi) const
|
---|
163 | {
|
---|
164 | psi=mod(psi,pi2);
|
---|
165 | return ConvToSphere(psi).ETheta();
|
---|
166 | }
|
---|
167 |
|
---|
168 | double Circle::SepAngleTanEPhi02PI(double psi) const
|
---|
169 | {
|
---|
170 | psi=mod(psi,pi2);
|
---|
171 | UnitVector pol=this->TanOnCircle(psi);
|
---|
172 | UnitVector ephi=this->EPhi(psi);
|
---|
173 | double angle=pol.SepAngle(ephi);
|
---|
174 | if( pol.Z() <= 0 ) angle=pi2-angle;
|
---|
175 | return angle;
|
---|
176 | }
|
---|
177 |
|
---|
178 | Circle& Circle::operator=(const Circle& c)
|
---|
179 | {
|
---|
180 | if( this != &c )
|
---|
181 | {
|
---|
182 | UnitVector temp(c.Omega());
|
---|
183 | SetCircle(temp,c.ApertureAngle());
|
---|
184 | }
|
---|
185 | return *this;
|
---|
186 | }
|
---|
187 |
|
---|
188 | bool Circle::operator==(const Circle& c) const
|
---|
189 | {
|
---|
190 | bool flag;
|
---|
191 | if( this == &c ) flag=true;
|
---|
192 | else flag=false;
|
---|
193 | return flag;
|
---|
194 | }
|
---|
195 |
|
---|
196 | bool Circle::operator!=(const Circle& c) const
|
---|
197 | {
|
---|
198 | return (bool)(1-(this->operator==(c)));
|
---|
199 | }
|
---|
200 |
|
---|
201 | void Circle::Print(ostream& os) const
|
---|
202 | {
|
---|
203 | os << "1 - Circle - Axe de Spin Unitaire : " << _spinunitaxis << endl;
|
---|
204 | os << "1 - Circle - Axe de Spin : " << _spinaxis << endl;
|
---|
205 | os << "2 - Circle - Angle d'ouverture : " << _angouv << endl;
|
---|
206 | os << "3 - Circle - Theta,Phi : " << _theta << "," << _phi << endl;
|
---|
207 | os << "4 - Circle - x,y,z : " << _x << "," << _y << "," << _z << endl;
|
---|
208 | }
|
---|