[262] | 1 | #include <math.h>
|
---|
[2615] | 2 | #include "sopnamsp.h"
|
---|
[262] | 3 | #include "circle.h"
|
---|
[568] | 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 | //++
|
---|
[262] | 20 | Circle::Circle()
|
---|
[568] | 21 | //
|
---|
| 22 | //--
|
---|
[262] | 23 | {
|
---|
| 24 | UnitVector temp;
|
---|
| 25 | SetCircle(temp,M_PI/2.);
|
---|
| 26 | }
|
---|
[568] | 27 | //++
|
---|
[262] | 28 | Circle::Circle(double theta, double phi, double aperture)
|
---|
[568] | 29 | //
|
---|
| 30 | //--
|
---|
[262] | 31 | {
|
---|
| 32 | UnitVector temp(theta,phi);
|
---|
| 33 | SetCircle(temp,aperture);
|
---|
| 34 | }
|
---|
[568] | 35 | //++
|
---|
[262] | 36 | Circle::Circle(double x, double y, double z, double aperture)
|
---|
[568] | 37 | //
|
---|
| 38 | //--
|
---|
[262] | 39 | {
|
---|
| 40 | UnitVector temp(x,y,z);
|
---|
| 41 | SetCircle(temp,aperture);
|
---|
| 42 | }
|
---|
[568] | 43 | //++
|
---|
[262] | 44 | Circle::Circle(const Vector3d& v, double aperture)
|
---|
[568] | 45 | //
|
---|
| 46 | //--
|
---|
[262] | 47 | {
|
---|
| 48 | UnitVector temp=v;
|
---|
| 49 | SetCircle(temp,aperture);
|
---|
| 50 | }
|
---|
[568] | 51 | //++
|
---|
[262] | 52 | Circle::Circle(const Circle& c)
|
---|
[568] | 53 | //
|
---|
| 54 | // copy constructor
|
---|
| 55 | //--
|
---|
[262] | 56 | {
|
---|
[1758] | 57 | UnitVector temp= c.Omega();
|
---|
[262] | 58 | SetCircle(temp,c._angouv);
|
---|
| 59 | }
|
---|
[568] | 60 | //++
|
---|
| 61 | // Titre Public Methods
|
---|
| 62 | //--
|
---|
| 63 | //++
|
---|
[262] | 64 | void Circle::SetCircle(const UnitVector& temp, double aperture)
|
---|
[568] | 65 | //
|
---|
| 66 | //--
|
---|
[262] | 67 | {
|
---|
[1758] | 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();
|
---|
[262] | 87 | }
|
---|
[568] | 88 | //++
|
---|
[262] | 89 | void Circle::SetSpinAxis(double theta, double phi)
|
---|
[568] | 90 | //
|
---|
| 91 | //--
|
---|
[262] | 92 | {
|
---|
| 93 | UnitVector temp(theta,phi);
|
---|
| 94 | SetCircle(temp,_angouv);
|
---|
| 95 | }
|
---|
[568] | 96 | //++
|
---|
[262] | 97 | void Circle::SetSpinAxis(const Vector3d& u)
|
---|
[568] | 98 | //
|
---|
| 99 | //--
|
---|
[262] | 100 | {
|
---|
| 101 | UnitVector temp=u;
|
---|
| 102 | SetCircle(temp,_angouv);
|
---|
| 103 | }
|
---|
[568] | 104 | //++
|
---|
[262] | 105 | void Circle::SetSpinAxis(double x, double y, double z)
|
---|
[568] | 106 | //
|
---|
| 107 | //--
|
---|
[262] | 108 | {
|
---|
| 109 | UnitVector temp(x,y,z);
|
---|
| 110 | SetCircle(temp,_angouv);
|
---|
| 111 | }
|
---|
[568] | 112 | //++
|
---|
[262] | 113 | void Circle::SetApertureAngle(double aperture)
|
---|
[568] | 114 | //
|
---|
| 115 | //--
|
---|
[262] | 116 | {
|
---|
| 117 | SetCircle(_spinunitaxis,aperture);
|
---|
| 118 | }
|
---|
[568] | 119 | //++
|
---|
[262] | 120 | void Circle::SetApertureAngle(const Circle& c)
|
---|
[568] | 121 | //
|
---|
| 122 | //--
|
---|
[262] | 123 | {
|
---|
| 124 | SetCircle(_spinunitaxis,c._angouv);
|
---|
| 125 | }
|
---|
[1758] | 126 |
|
---|
[568] | 127 | //++
|
---|
[470] | 128 | UnitVector Circle::ConvToSphere(double psi) const
|
---|
[568] | 129 | //
|
---|
| 130 | // Return UnitVector corresponding to a given position donnee on the circle
|
---|
| 131 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 148 | //++
|
---|
[262] | 149 | UnitVector Circle::TanOnCircle(double psi) const
|
---|
[568] | 150 | //
|
---|
| 151 | // Return UnitVector corresponding to the tangent to the circle
|
---|
| 152 | // at given position on the circle.
|
---|
| 153 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 168 | //++
|
---|
[262] | 169 | UnitVector Circle::EPhi(double psi) const
|
---|
[568] | 170 | //
|
---|
| 171 | // Return the vector tangent to the sphere in the plane (xy)
|
---|
| 172 | // at a given position on the circle.
|
---|
| 173 | //--
|
---|
[262] | 174 | {
|
---|
| 175 | psi=mod(psi,pi2);
|
---|
[470] | 176 | return ConvToSphere(psi).EPhi();
|
---|
[262] | 177 | }
|
---|
[568] | 178 | //++
|
---|
[262] | 179 | UnitVector Circle::ETheta(double psi) const
|
---|
[568] | 180 | //
|
---|
| 181 | // Return the other tangent vector( orthogonal to EPhi)--
|
---|
| 182 | // see previous method
|
---|
| 183 | //--
|
---|
[262] | 184 | {
|
---|
| 185 | psi=mod(psi,pi2);
|
---|
[470] | 186 | return ConvToSphere(psi).ETheta();
|
---|
[262] | 187 | }
|
---|
[568] | 188 | //++
|
---|
[262] | 189 | double Circle::SepAngleTanEPhi02PI(double psi) const
|
---|
[568] | 190 | //
|
---|
| 191 | // Return separation angle in [0,2Pi] at a given position on the
|
---|
| 192 | // circle and EPhi
|
---|
| 193 | //--
|
---|
[262] | 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 | }
|
---|
[568] | 202 | //++
|
---|
| 203 | void 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 | //--
|
---|
[262] | 223 |
|
---|
| 224 | Circle& 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 | }
|
---|
[568] | 233 | //++
|
---|
[262] | 234 | bool Circle::operator==(const Circle& c) const
|
---|
[568] | 235 | //
|
---|
| 236 | //--
|
---|
[262] | 237 | {
|
---|
| 238 | bool flag;
|
---|
| 239 | if( this == &c ) flag=true;
|
---|
| 240 | else flag=false;
|
---|
| 241 | return flag;
|
---|
| 242 | }
|
---|
[568] | 243 | //++
|
---|
[262] | 244 | bool Circle::operator!=(const Circle& c) const
|
---|
[568] | 245 | //
|
---|
| 246 | //--
|
---|
[262] | 247 | {
|
---|
| 248 | return (bool)(1-(this->operator==(c)));
|
---|
| 249 | }
|
---|
[1758] | 250 | //
|
---|
[1770] | 251 | bool Circle::Intersection(const Circle& c) const
|
---|
[1758] | 252 | {
|
---|
| 253 | double alphak= _angouv;
|
---|
[1770] | 254 | double alphal= c._angouv;
|
---|
[1758] | 255 | Vector3d ok= _spinaxis;
|
---|
[1770] | 256 | Vector3d ol= c._spinaxis;
|
---|
[1758] | 257 | double gamma= ok.SepAngle(ol);
|
---|
| 258 |
|
---|
[1770] | 259 | if(fabs(alphak-alphal) < gamma && gamma <= (alphak+alphal) && this != &c) {
|
---|
[1758] | 260 | return true;
|
---|
| 261 | } else {
|
---|
| 262 | return false;
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 | //
|
---|
[1770] | 266 | bool Circle::Intersection(const Circle& c, double* psi) const
|
---|
[1758] | 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 | }
|
---|