[262] | 1 | #include <math.h>
|
---|
| 2 | #include "circle.h"
|
---|
[568] | 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 | //++
|
---|
[262] | 19 | Circle::Circle()
|
---|
[568] | 20 | //
|
---|
| 21 | //--
|
---|
[262] | 22 | {
|
---|
| 23 | UnitVector temp;
|
---|
| 24 | SetCircle(temp,M_PI/2.);
|
---|
| 25 | }
|
---|
[568] | 26 | //++
|
---|
[262] | 27 | Circle::Circle(double theta, double phi, double aperture)
|
---|
[568] | 28 | //
|
---|
| 29 | //--
|
---|
[262] | 30 | {
|
---|
| 31 | UnitVector temp(theta,phi);
|
---|
| 32 | SetCircle(temp,aperture);
|
---|
| 33 | }
|
---|
[568] | 34 | //++
|
---|
[262] | 35 | Circle::Circle(double x, double y, double z, double aperture)
|
---|
[568] | 36 | //
|
---|
| 37 | //--
|
---|
[262] | 38 | {
|
---|
| 39 | UnitVector temp(x,y,z);
|
---|
| 40 | SetCircle(temp,aperture);
|
---|
| 41 | }
|
---|
[568] | 42 | //++
|
---|
[262] | 43 | Circle::Circle(const Vector3d& v, double aperture)
|
---|
[568] | 44 | //
|
---|
| 45 | //--
|
---|
[262] | 46 | {
|
---|
| 47 | UnitVector temp=v;
|
---|
| 48 | SetCircle(temp,aperture);
|
---|
| 49 | }
|
---|
[568] | 50 | //++
|
---|
[262] | 51 | Circle::Circle(const Circle& c)
|
---|
[568] | 52 | //
|
---|
| 53 | // copy constructor
|
---|
| 54 | //--
|
---|
[262] | 55 | {
|
---|
| 56 | UnitVector temp=c.Omega();
|
---|
| 57 | SetCircle(temp,c._angouv);
|
---|
| 58 | }
|
---|
[568] | 59 | //++
|
---|
| 60 | // Titre Public Methods
|
---|
| 61 | //--
|
---|
| 62 | //++
|
---|
[262] | 63 | void Circle::SetCircle(const UnitVector& temp, double aperture)
|
---|
[568] | 64 | //
|
---|
| 65 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 76 | //++
|
---|
[262] | 77 | void Circle::SetSpinAxis(double theta, double phi)
|
---|
[568] | 78 | //
|
---|
| 79 | //--
|
---|
[262] | 80 | {
|
---|
| 81 | UnitVector temp(theta,phi);
|
---|
| 82 | SetCircle(temp,_angouv);
|
---|
| 83 | }
|
---|
[568] | 84 | //++
|
---|
[262] | 85 | void Circle::SetSpinAxis(const Vector3d& u)
|
---|
[568] | 86 | //
|
---|
| 87 | //--
|
---|
[262] | 88 | {
|
---|
| 89 | UnitVector temp=u;
|
---|
| 90 | SetCircle(temp,_angouv);
|
---|
| 91 | }
|
---|
[568] | 92 | //++
|
---|
[262] | 93 | void Circle::SetSpinAxis(double x, double y, double z)
|
---|
[568] | 94 | //
|
---|
| 95 | //--
|
---|
[262] | 96 | {
|
---|
| 97 | UnitVector temp(x,y,z);
|
---|
| 98 | SetCircle(temp,_angouv);
|
---|
| 99 | }
|
---|
[568] | 100 | //++
|
---|
[262] | 101 | void Circle::SetApertureAngle(double aperture)
|
---|
[568] | 102 | //
|
---|
| 103 | //--
|
---|
[262] | 104 | {
|
---|
| 105 | SetCircle(_spinunitaxis,aperture);
|
---|
| 106 | }
|
---|
[568] | 107 | //++
|
---|
[262] | 108 | void Circle::SetApertureAngle(const Circle& c)
|
---|
[568] | 109 | //
|
---|
| 110 | //--
|
---|
[262] | 111 | {
|
---|
| 112 | SetCircle(_spinunitaxis,c._angouv);
|
---|
| 113 | }
|
---|
[568] | 114 | //++
|
---|
[262] | 115 | bool Circle::Intersection(const Circle& c, double* psi) const
|
---|
[568] | 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 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 170 | //++
|
---|
[470] | 171 | UnitVector Circle::ConvToSphere(double psi) const
|
---|
[568] | 172 | //
|
---|
| 173 | // Return UnitVector corresponding to a given position donnee on the circle
|
---|
| 174 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 191 | //++
|
---|
[262] | 192 | UnitVector Circle::TanOnCircle(double psi) const
|
---|
[568] | 193 | //
|
---|
| 194 | // Return UnitVector corresponding to the tangent to the circle
|
---|
| 195 | // at given position on the circle.
|
---|
| 196 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 211 | //++
|
---|
[262] | 212 | UnitVector Circle::EPhi(double psi) const
|
---|
[568] | 213 | //
|
---|
| 214 | // Return the vector tangent to the sphere in the plane (xy)
|
---|
| 215 | // at a given position on the circle.
|
---|
| 216 | //--
|
---|
[262] | 217 | {
|
---|
| 218 | psi=mod(psi,pi2);
|
---|
[470] | 219 | return ConvToSphere(psi).EPhi();
|
---|
[262] | 220 | }
|
---|
[568] | 221 | //++
|
---|
[262] | 222 | UnitVector Circle::ETheta(double psi) const
|
---|
[568] | 223 | //
|
---|
| 224 | // Return the other tangent vector( orthogonal to EPhi)--
|
---|
| 225 | // see previous method
|
---|
| 226 | //--
|
---|
[262] | 227 | {
|
---|
| 228 | psi=mod(psi,pi2);
|
---|
[470] | 229 | return ConvToSphere(psi).ETheta();
|
---|
[262] | 230 | }
|
---|
[568] | 231 | //++
|
---|
[262] | 232 | double Circle::SepAngleTanEPhi02PI(double psi) const
|
---|
[568] | 233 | //
|
---|
| 234 | // Return separation angle in [0,2Pi] at a given position on the
|
---|
| 235 | // circle and EPhi
|
---|
| 236 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 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 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 276 | //++
|
---|
[262] | 277 | bool Circle::operator==(const Circle& c) const
|
---|
[568] | 278 | //
|
---|
| 279 | //--
|
---|
[262] | 280 | {
|
---|
| 281 | bool flag;
|
---|
| 282 | if( this == &c ) flag=true;
|
---|
| 283 | else flag=false;
|
---|
| 284 | return flag;
|
---|
| 285 | }
|
---|
[568] | 286 | //++
|
---|
[262] | 287 | bool Circle::operator!=(const Circle& c) const
|
---|
[568] | 288 | //
|
---|
| 289 | //--
|
---|
[262] | 290 | {
|
---|
| 291 | return (bool)(1-(this->operator==(c)));
|
---|
| 292 | }
|
---|