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