MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
ot_boite_3d.cpp
Aller à la documentation de ce fichier.
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// ot_boite_3d.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:53:59 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 
23 
24 #include "ot_boite_3d.h"
25 #include <math.h>
26 #include <algorithm>
27 
28 #define PETIT 1e-8
29 
30 BOITE_3D::BOITE_3D(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):x(xmin),y(ymin),z(zmin),dx(xmax-xmin),dy(ymax-ymin),dz(zmax-zmin)
31 {
32  bool recentrage=false;
33  if ((dx<PETIT) && (dy<PETIT) && (dz<PETIT)) recentrage=true;
34  if (dx<PETIT)
35  {
36  dx=PETIT;
37  if (recentrage==true) x=x-dx/2.;
38  }
39  if (dy<PETIT)
40  {
41  dy=PETIT;
42  if (recentrage==true) y=y-dy/2.;
43  }
44  if (dz<PETIT)
45  {
46  dz=PETIT;
47  if (recentrage==true) z=z-dz/2.;
48  }
49 }
50 
52 {
53 }
54 
55 void BOITE_3D::reinit(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
56 {
57  x=xmin;
58  y=ymin;
59  z=zmin;
60  dx=xmax-xmin;
61  dy=ymax-ymin;
62  dz=zmax-zmin;
63  bool recentrage=false;
64  if ((dx<PETIT) && (dy<PETIT) && (dz<PETIT)) recentrage=true;
65  if (dx<PETIT)
66  {
67  dx=PETIT;
68  if (recentrage==true) x=x-dx/2.;
69  }
70  if (dy<PETIT)
71  {
72  dy=PETIT;
73  if (recentrage==true) y=y-dy/2.;
74  }
75  if (dz<PETIT)
76  {
77  dz=PETIT;
78  if (recentrage==true) z=z-dz/2.;
79  }
80 }
81 
83 {
84  x=boite.x;
85  y=boite.y;
86  z=boite.z;
87  dx=boite.dx;
88  dy=boite.dy;
89  dz=boite.dz;
90 }
91 
92 BOITE_3D::BOITE_3D(const BOITE_3D& mdd):x(mdd.x),y(mdd.y),z(mdd.z),dx(mdd.dx),dy(mdd.dy),dz(mdd.dz)
93 {
94 }
95 
96 BOITE_3D::BOITE_3D(BOITE_3D& mdd):x(mdd.x),y(mdd.y),z(mdd.z),dx(mdd.dx),dy(mdd.dy),dz(mdd.dz)
97 {
98 }
99 
101 {
102 }
103 
104 double BOITE_3D::get_xmin(void)
105 {
106  return x;
107 }
108 
109 double BOITE_3D::get_xmax(void)
110 {
111  return (x+dx);
112 }
113 
114 double BOITE_3D::get_ymin(void)
115 {
116  return y;
117 }
118 
119 double BOITE_3D::get_ymax(void)
120 {
121  return (y+dy);
122 }
123 
124 double BOITE_3D::get_zmin(void)
125 {
126  return z;
127 }
128 
129 double BOITE_3D::get_zmax(void)
130 {
131  return (z+dz);
132 }
133 
134 /*BOITE_3D BOITE_3D::operator=(BOITE_3D& boite)
135 {
136  x=boite.x;
137  y=boite.y;
138  z=boite.z;
139  dx=boite.dx;
140  dy=boite.dy;
141  dz=boite.dz;
142  return *this;
143 }*/
145 {
146  return (0.5*sqrt(dx*dx+dy*dy+dz*dz));
147 }
148 
149 void BOITE_3D::get_centre(double *coo)
150 {
151  coo[0]=x+dx*0.5;
152  coo[1]=y+dy*0.5;
153  coo[2]=z+dz*0.5;
154 }
155 
157 {
158  return x+dx*0.5;
159 }
160 
162 {
163  return y+dy*0.5;
164 }
165 
167 {
168  return z+dz*0.5;
169 }
170 
172 {
173  return(get_xmax()-get_xmin())*(get_ymax()-get_ymin())*(get_zmax()-get_zmin());
174 }
175 
177 {
178 double centre[3];
179 get_centre(centre);
180 dx=dx*f;
181 dy=dy*f;
182 dz=dz*f;
183 reinit(centre[0]-dx/2.,centre[1]-dy/2.,centre[2]-dz/2.,centre[0]+dx/2.,centre[1]+dy/2.,centre[2]+dz/2.);
184 }
185 
187 {
188  if ( x+dx>=boite.x)
189  if ( y+dy>=boite.y)
190  if ( z+dz>=boite.z)
191  if ( x<(boite.x+boite.dx))
192  if ( y<(boite.y+boite.dy))
193  if ( z<(boite.z+boite.dz))
194  return 1;
195  return 0;
196 }
197 
198 
200 {
201  if((boite.get_xmin()<=get_xmax() && boite.get_xmax()>=get_xmin()) || (get_xmin()<=boite.get_xmax() && get_xmax()>=boite.get_xmin()))
202  if((boite.get_ymin()<=get_ymax() && boite.get_ymax()>=get_ymin()) || (get_ymin()<=boite.get_ymax() && get_ymax()>=boite.get_ymin()))
203  if((boite.get_zmin()<=get_zmax() && boite.get_zmax()>=get_zmin()) || (get_zmin()<=boite.get_zmax() && get_zmax()>=boite.get_zmin())) return 1;
204  return 0;
205 }
206 
207 
208 
209 int BOITE_3D::operator*(const BOITE_3D& boite)
210 {
211  if ( x+dx>=boite.x)
212  if ( y+dy>=boite.y)
213  if ( z+dz>=boite.z)
214  if ( x<(boite.x+boite.dx))
215  if ( y<(boite.y+boite.dy))
216  if ( z<(boite.z+boite.dz))
217  return 1;
218  return 0;
219 }
220 
221 
222 BOITE_3D operator&(const BOITE_3D& boite1,const BOITE_3D& boite2)
223 {
224  double xmin1=boite1.x;
225  double ymin1=boite1.y;
226  double zmin1=boite1.z;
227  double xmin2=boite2.x;
228  double ymin2=boite2.y;
229  double zmin2=boite2.z;
230  double xmax1=boite1.x+boite1.dx;
231  double ymax1=boite1.y+boite1.dy;
232  double zmax1=boite1.z+boite1.dz;
233  double xmax2=boite2.x+boite2.dx;
234  double ymax2=boite2.y+boite2.dy;
235  double zmax2=boite2.z+boite2.dz;
236  double xmin=std::max(xmin1,xmin2);
237  double ymin=std::max(ymin1,ymin2);
238  double zmin=std::max(zmin1,zmin2);
239  double xmax=std::min(xmax1,xmax2);
240  double ymax=std::min(ymax1,ymax2);
241  double zmax=std::min(zmax1,zmax2);
242  BOITE_3D tmp(xmin,ymin,zmin,xmax,ymax,zmax);
243  return tmp;
244 }
245 
246 
247 BOITE_3D operator+(const BOITE_3D& boite1,const BOITE_3D& boite2)
248 {
249  double xmin1=boite1.x;
250  double ymin1=boite1.y;
251  double zmin1=boite1.z;
252  double xmin2=boite2.x;
253  double ymin2=boite2.y;
254  double zmin2=boite2.z;
255  double xmax1=boite1.x+boite1.dx;
256  double ymax1=boite1.y+boite1.dy;
257  double zmax1=boite1.z+boite1.dz;
258  double xmax2=boite2.x+boite2.dx;
259  double ymax2=boite2.y+boite2.dy;
260  double zmax2=boite2.z+boite2.dz;
261  double xmin=std::min(xmin1,xmin2);
262  double ymin=std::min(ymin1,ymin2);
263  double zmin=std::min(zmin1,zmin2);
264  double xmax=std::max(xmax1,xmax2);
265  double ymax=std::max(ymax1,ymax2);
266  double zmax=std::max(zmax1,zmax2);
267  BOITE_3D tmp(xmin,ymin,zmin,xmax,ymax,zmax);
268  return tmp;
269 }
270 int BOITE_3D::contient(double xx,double yy,double zz)
271 {
272  if (xx>=x)
273  if (yy>=y)
274  if (zz>=z)
275  if (xx<=x+dx)
276  if (yy<=y+dy)
277  if (zz<=z+dz)
278  return 1;
279 
280 
281  return 0;
282 }
283 
284 
285 
PETIT
#define PETIT
Definition: ot_boite_3d.cpp:28
BOITE_3D::get_xmin
double get_xmin(void)
Definition: ot_boite_3d.cpp:104
BOITE_3D::get_centre
void get_centre(double *coo)
Definition: ot_boite_3d.cpp:149
BOITE_3D::y
double y
Definition: ot_boite_3d.h:64
BOITE_3D::get_xcentre
double get_xcentre(void)
Definition: ot_boite_3d.cpp:156
BOITE_3D::dx
double dx
Definition: ot_boite_3d.h:66
BOITE_3D::get_zmax
double get_zmax(void)
Definition: ot_boite_3d.cpp:129
BOITE_3D::get_ymin
double get_ymin(void)
Definition: ot_boite_3d.cpp:114
BOITE_3D::get_zcentre
double get_zcentre(void)
Definition: ot_boite_3d.cpp:166
f
double f(double x, long nb, double *xfonc, double *fonc, double eng, double eni, double lambda, double nor, double *fonc2)
Definition: fct_generateur_calibrage.cpp:96
BOITE_3D::x
double x
Definition: ot_boite_3d.h:63
BOITE_3D::get_xmax
double get_xmax(void)
Definition: ot_boite_3d.cpp:109
BOITE_3D::get_ycentre
double get_ycentre(void)
Definition: ot_boite_3d.cpp:161
BOITE_3D::get_volume
double get_volume(void)
Definition: ot_boite_3d.cpp:171
BOITE_3D::BOITE_3D
BOITE_3D(void)
Definition: ot_boite_3d.cpp:51
BOITE_3D::reinit
void reinit(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Definition: ot_boite_3d.cpp:55
BOITE_3D::get_ymax
double get_ymax(void)
Definition: ot_boite_3d.cpp:119
BOITE_3D::dz
double dz
Definition: ot_boite_3d.h:68
operator+
BOITE_3D operator+(const BOITE_3D &boite1, const BOITE_3D &boite2)
Definition: ot_boite_3d.cpp:247
BOITE_3D
Definition: ot_boite_3d.h:27
BOITE_3D::get_rayon
double get_rayon(void)
Definition: ot_boite_3d.cpp:144
sqrt
double2 sqrt(double2 &val)
Definition: ot_doubleprecision.cpp:345
ot_boite_3d.h
BOITE_3D::get_zmin
double get_zmin(void)
Definition: ot_boite_3d.cpp:124
BOITE_3D::dy
double dy
Definition: ot_boite_3d.h:67
BOITE_3D::contient
int contient(double x, double y, double z)
Definition: ot_boite_3d.cpp:270
BOITE_3D::operator*
int operator*(BOITE_3D &boite)
Definition: ot_boite_3d.cpp:186
BOITE_3D::~BOITE_3D
virtual ~BOITE_3D()
Definition: ot_boite_3d.cpp:100
BOITE_3D::change_grosseur
void change_grosseur(double f)
Definition: ot_boite_3d.cpp:176
BOITE_3D::z
double z
Definition: ot_boite_3d.h:65
BOITE_3D::get_intersection
int get_intersection(BOITE_3D &boite1)
Definition: ot_boite_3d.cpp:199
operator&
BOITE_3D operator&(const BOITE_3D &boite1, const BOITE_3D &boite2)
Definition: ot_boite_3d.cpp:222