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