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