| 1 | #include "sopnamsp.h" | 
|---|
| 2 | #include "machdefs.h" | 
|---|
| 3 | #include <math.h> | 
|---|
| 4 | #include <iostream> | 
|---|
| 5 | #include "utilgeom.h" | 
|---|
| 6 | //++ | 
|---|
| 7 | // Titre        Some utilitary functions for geometry (utilgeom.h)... | 
|---|
| 8 | //-- | 
|---|
| 9 | //++ | 
|---|
| 10 | int sign(double d) | 
|---|
| 11 | // | 
|---|
| 12 | //-- | 
|---|
| 13 | { | 
|---|
| 14 | return (d >= 0) - (d < 0); | 
|---|
| 15 | } | 
|---|
| 16 | //++ | 
|---|
| 17 | double absd(double d) | 
|---|
| 18 | // | 
|---|
| 19 | //-- | 
|---|
| 20 | { | 
|---|
| 21 | return sqrt(d*d); | 
|---|
| 22 | } | 
|---|
| 23 | //++ | 
|---|
| 24 | double mod(double d, double periode) | 
|---|
| 25 | // | 
|---|
| 26 | //-- | 
|---|
| 27 | { | 
|---|
| 28 | if( d >= 0 ) return d-floor(d/periode)*periode; | 
|---|
| 29 | else return d-ceil(d/periode)*periode+periode; | 
|---|
| 30 | } | 
|---|
| 31 | //++ | 
|---|
| 32 | void swap(double& d1, double& d2) | 
|---|
| 33 | // | 
|---|
| 34 | //-- | 
|---|
| 35 | { | 
|---|
| 36 | double temp; | 
|---|
| 37 | temp=d2; | 
|---|
| 38 | d2=d1; | 
|---|
| 39 | d1=temp; | 
|---|
| 40 | } | 
|---|
| 41 | //++ | 
|---|
| 42 | double min(double d1, double d2) | 
|---|
| 43 | // | 
|---|
| 44 | //-- | 
|---|
| 45 | { | 
|---|
| 46 | if( d1 >= d2 ) return d2; | 
|---|
| 47 | else return d1; | 
|---|
| 48 | } | 
|---|
| 49 | //++ | 
|---|
| 50 | double max(double d1, double d2) | 
|---|
| 51 | // | 
|---|
| 52 | //-- | 
|---|
| 53 | { | 
|---|
| 54 | return -min(-d1,-d2); | 
|---|
| 55 | } | 
|---|
| 56 | //++ | 
|---|
| 57 | int arrondi(double d) | 
|---|
| 58 | // | 
|---|
| 59 | //-- | 
|---|
| 60 | { | 
|---|
| 61 | return (int)(((d-floor(d)) >= 0.5)*ceil(d)+((d-floor(d)) < 0.5)*floor(d)); | 
|---|
| 62 | } | 
|---|
| 63 | //++ | 
|---|
| 64 | long rangijd(int nc, int i, int j, int d) | 
|---|
| 65 | // | 
|---|
| 66 | //-- | 
|---|
| 67 | { | 
|---|
| 68 | if( i < j ) return 2*i*(2*nc-i-1)+4*(j-i-1)+d; | 
|---|
| 69 | if( i > j ) return 2*j*(2*nc-j-1)+4*(i-j-1)+d+2; | 
|---|
| 70 | if( i == j ) | 
|---|
| 71 | { | 
|---|
| 72 | cout << "pas d'intersection entre le cercle " << i | 
|---|
| 73 | << " et le cercle " << j << "." << endl; | 
|---|
| 74 | return -1; | 
|---|
| 75 | } | 
|---|
| 76 | else return -1; | 
|---|
| 77 | } | 
|---|
| 78 | //++ | 
|---|
| 79 | long rangdiff(int nc, int i, int j, int d) | 
|---|
| 80 | // | 
|---|
| 81 | //-- | 
|---|
| 82 | { | 
|---|
| 83 | if( i == j ) | 
|---|
| 84 | { | 
|---|
| 85 | cout << "diff n'est pas defini entre le cercle " << i | 
|---|
| 86 | << " et le cercle " << j << "." << endl; | 
|---|
| 87 | return 0; | 
|---|
| 88 | } | 
|---|
| 89 | int indm=(int)min(i,j); | 
|---|
| 90 | int indM=(int)max(i,j); | 
|---|
| 91 | return indm*(2*nc-indm-1)+2*(indM-indm-1)+d; | 
|---|
| 92 | } | 
|---|
| 93 | //++ | 
|---|
| 94 | long rangik(int NtotEch, int i, int k) | 
|---|
| 95 | // | 
|---|
| 96 | //-- | 
|---|
| 97 | { | 
|---|
| 98 | return NtotEch*i+k; | 
|---|
| 99 | } | 
|---|
| 100 | //++ | 
|---|
| 101 | long ranghk(int NtotEch, int h, int k) | 
|---|
| 102 | // | 
|---|
| 103 | //-- | 
|---|
| 104 | { | 
|---|
| 105 | return NtotEch*h+k; | 
|---|
| 106 | } | 
|---|
| 107 | //++ | 
|---|
| 108 | double scangle(double sinus, double cosinus) | 
|---|
| 109 | // | 
|---|
| 110 | //-- | 
|---|
| 111 | {       // Modifie par D. Y. pour eviter des plantages aux petis angles | 
|---|
| 112 | double eps=1.e-10; | 
|---|
| 113 | if( fabs(1.-sinus*sinus-cosinus*cosinus) > eps) | 
|---|
| 114 | {      // On renormalise D.Y. | 
|---|
| 115 | // cerr << "angle non valide: "<< "sinus = " << sinus << " cosinus = " << cosinus << '\n'; // BUGGG | 
|---|
| 116 | double norm= cosinus*cosinus+sinus*sinus; | 
|---|
| 117 | cosinus=cosinus/norm; | 
|---|
| 118 | sinus=sinus/norm; | 
|---|
| 119 | } | 
|---|
| 120 | if( fabs(cosinus) >1. ) cosinus=1.*copysign(1.,cosinus); | 
|---|
| 121 | if( fabs(sinus) >1. ) sinus=1.*copysign(1.,sinus); | 
|---|
| 122 | /*  if( fabs(sinus) == 0. ) sinus=0.; | 
|---|
| 123 | if( fabs(cosinus) == 0. ) cosinus=0.; | 
|---|
| 124 | */ | 
|---|
| 125 | return acos(cosinus)*copysign(1,sinus); | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|