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