summaryrefslogtreecommitdiff
path: root/src/GProp/GProp_VelGProps.cxx
blob: 10458e76d003851af420e83148a05fd1f674b5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#include <GProp_VelGProps.ixx>
#include <Standard_NotImplemented.hxx>
#include <gp.hxx>
#include <GProp.hxx>
#include <math_Matrix.hxx>
#include <math_Vector.hxx>
#include <math_Jacobi.hxx>


GProp_VelGProps::GProp_VelGProps(){}

void GProp_VelGProps::SetLocation(const gp_Pnt& VLocation)
{
  loc =VLocation;
}


GProp_VelGProps::GProp_VelGProps(const gp_Cylinder&    S,
				 const Standard_Real Alpha1,
				 const Standard_Real Alpha2,
				 const Standard_Real Z1,
				 const Standard_Real Z2,
				 const gp_Pnt&        VLocation)
{
  SetLocation(VLocation);
  Perform(S,Alpha1,Alpha2,Z1,Z2);
}

GProp_VelGProps::GProp_VelGProps(const gp_Cone&    S,
				 const Standard_Real  Alpha1,
				 const Standard_Real Alpha2,
				 const Standard_Real Z1,
				 const Standard_Real Z2,
				 const gp_Pnt&        VLocation)
{
  SetLocation(VLocation);
  Perform(S,Alpha1,Alpha2,Z1,Z2);
}

GProp_VelGProps::GProp_VelGProps(const gp_Sphere&    S,
				 const Standard_Real Teta1,
				 const Standard_Real Teta2,
				 const Standard_Real Alpha1,
				 const Standard_Real Alpha2,
				 const gp_Pnt&        VLocation)
{
  SetLocation(VLocation);
  Perform(S,Teta1,Teta2,Alpha1,Alpha2);
}


GProp_VelGProps::GProp_VelGProps(const gp_Torus&    S,
				 const Standard_Real Teta1,
				 const Standard_Real Teta2,
				 const Standard_Real Alpha1,
				 const Standard_Real Alpha2,
				 const gp_Pnt&        VLocation)
{
  SetLocation(VLocation);
  Perform(S,Teta1,Teta2,Alpha1,Alpha2);
}

void GProp_VelGProps::Perform(const gp_Cylinder&    S,
			      const Standard_Real  Alpha1,
			      const Standard_Real Alpha2,
			      const Standard_Real Z1,
			      const Standard_Real Z2)
{
  Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
  S.Location().Coord(X0,Y0,Z0);
  Standard_Real Rayon = S.Radius();
  S.Position().XDirection().Coord(Xa1,Ya1,Za1);
  S.Position().YDirection().Coord(Xa2,Ya2,Za2);
  S.Position().Direction().Coord(Xa3,Ya3,Za3);
  dim = Rayon*Rayon*(Z2-Z1)/2.;
  Standard_Real SA2 = Sin(Alpha2);
  Standard_Real SA1 = Sin(Alpha1);
  Standard_Real CA2 = Cos(Alpha2);
  Standard_Real CA1 = Cos(Alpha1);
  Standard_Real Dsin = SA2-SA1; 
  Standard_Real Dcos = CA1-CA2; 
  Standard_Real Coef = Rayon/(Alpha2-Alpha1);

  g.SetCoord(X0+(Coef*(Xa1*Dsin+Xa2*Dcos) ) + (Xa3*(Z2+Z1)/2.),
	     Y0+(Coef*(Ya1*Dsin+Ya2*Dcos) ) + (Ya3*(Z2+Z1)/2.),
	     Z0+(Coef*(Za1*Dsin+Za2*Dcos) ) + (Za3*(Z2+Z1)/2.) );
  
  Standard_Real ICn2 = dim/2. *( Alpha2-Alpha1 + SA2*CA2 - SA1*CA1 );  
  Standard_Real ISn2 = dim/2. *( Alpha2-Alpha1 - SA2*CA2 + SA1*CA1 );
  Standard_Real IZ2 = dim * (Alpha2-Alpha1)*(Z2*Z2+Z1*Z2+Z1*Z1);
  Standard_Real ICnSn = dim *(CA2*CA2-CA1*CA1)/2.;
  Standard_Real ICnz = dim *(Z2+Z1)/2.*Dsin;
  Standard_Real ISnz = dim *(Z2+Z1)/2.*Dcos;
  dim =(Alpha2-Alpha1)*dim;  

  math_Matrix Dm(1,3,1,3);

  Dm(1,1) = Rayon*Rayon*ISn2 + IZ2;
  Dm(2,2) = Rayon*Rayon*ICn2 + IZ2;
  Dm(3,3) = Rayon*Rayon*dim;
  Dm(1,2) = Dm(2,1) = -Rayon*Rayon*ICnSn;
  Dm(1,3) = Dm(3,1) = -Rayon*ICnz;
  Dm(3,2) = Dm(2,3) = -Rayon*ISnz;

  math_Matrix Passage (1,3,1,3);
  Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
  Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
  Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;

  math_Jacobi J(Dm);
  math_Vector V1(1,3),V2(1,3),V3(1,3);
  J.Vector(1,V1);
  V1.Multiply(Passage,V1);
  V1.Multiply(J.Value(1));
  J.Vector(2,V2);
  V2.Multiply(Passage,V2);
  V2.Multiply(J.Value(2));
  J.Vector(3,V3);
  V3.Multiply(Passage,V3);
  V3.Multiply(J.Value(3));

  inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
		    gp_XYZ(V1(2),V2(2),V3(2)),
		    gp_XYZ(V1(3),V2(3),V3(3)));
  gp_Mat Hop;
  GProp::HOperator(g,loc,dim,Hop);
  inertia = inertia+Hop;
}

void GProp_VelGProps::Perform(const gp_Cone&    S,
			      const Standard_Real Alpha1,
			      const Standard_Real Alpha2,
			      const Standard_Real Z1,
			      const Standard_Real Z2)
{
  Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
  S.Location().Coord(X0,Y0,Z0);
  S.Position().XDirection().Coord(Xa1,Ya1,Za1);
  S.Position().YDirection().Coord(Xa2,Ya2,Za2);
  S.Position().Direction().Coord(Xa3,Ya3,Za3);
  Standard_Real t =S.SemiAngle();
  Standard_Real Cnt = Cos(t);
  Standard_Real Snt = Sin(t); 
  Standard_Real R = S.RefRadius();
  Standard_Real Sn2 = Sin(Alpha2);
  Standard_Real Sn1 = Sin(Alpha1);
  Standard_Real Cn2 = Cos(Alpha2);
  Standard_Real Cn1 = Cos(Alpha1);
  Standard_Real ZZ = (Z2-Z1)*(Z2-Z1)*Cnt*Snt;
  Standard_Real Auxi1=  2*R +(Z2+Z1)*Snt;

  dim = ZZ*(Alpha2-Alpha1)*Auxi1/2.;

  Standard_Real R1 = R + Z1*Snt;
  Standard_Real R2 = R + Z2*Snt;
  Standard_Real Coef0 = (R1*R1+R1*R2+R2*R2);
  Standard_Real Iz = Cnt*(R*(Z2+Z1) + 2*Snt*(Z1*Z1+Z1*Z2+Z2*Z2)/3.)/Auxi1;
  Standard_Real Ix = Coef0*(Sn2-Sn1)/(Alpha2-Alpha1)/Auxi1;
  Standard_Real Iy = Coef0*(Cn1-Cn2)/(Alpha2-Alpha1)/Auxi1;

  g.SetCoord(X0 + Xa1*Ix + Xa2*Iy  + Xa3*Iz,
	     Y0 + Ya1*Ix + Ya2*Iy  + Ya3*Iz,
	     Z0 + Za1*Ix + Za2*Iy  + Za3*Iz);

  Standard_Real IR2 = ZZ*(R2*R2*R2+R2*R2*R1+R1*R1*R2+R1*R1*R1)/4.;
  Standard_Real ICn2  = IR2*(Alpha2-Alpha1+Cn2*Sn2-Cn1*Sn1)/2.;
  Standard_Real ISn2 = IR2*(Alpha2-Alpha1+Cn2*Sn2-Cn1*Sn1)/2.;
  Standard_Real IZ2  = ZZ*Cnt*Cnt*(Alpha2-Alpha1)*
                       (Z1*Z1*(R/3 + Z1*Snt/4) + 
			Z2*Z2*(R/3 + Z2*Snt/4) +
			Z1*Z2*(R/3 +Z1*Snt/4 +Z2*Snt/4));
  Standard_Real ICnSn = IR2*(Cn2*Cn2-Cn1*Cn1);
  Standard_Real ICnz = (Z1+Z2)*ZZ*Coef0*(Sn2-Sn1)/3;
  Standard_Real ISnz = (Z1+Z2)*ZZ*Coef0*(Cn1-Cn2)/3;    

   
  math_Matrix Dm(1,3,1,3);
  Dm(1,1) = ISn2 + IZ2;
  Dm(2,2) = ICn2 + IZ2;
  Dm(3,3) = IR2*(Alpha2-Alpha1);
  Dm(1,2) = Dm(2,1) = -ICnSn;
  Dm(1,3) = Dm(3,1) = -ICnz;
  Dm(3,2) = Dm(2,3) = -ISnz;

  math_Matrix Passage (1,3,1,3);
  Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
  Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
  Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;

  math_Jacobi J(Dm);
  math_Vector V1(1,3),V2(1,3),V3(1,3);
  J.Vector(1,V1);
  V1.Multiply(Passage,V1);
  V1.Multiply(J.Value(1));
  J.Vector(2,V2);
  V2.Multiply(Passage,V2);
  V2.Multiply(J.Value(2));
  J.Vector(3,V3);
  V3.Multiply(Passage,V3);
  V3.Multiply(J.Value(3));

  inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
		    gp_XYZ(V1(2),V2(2),V3(2)),
		    gp_XYZ(V1(3),V2(3),V3(3)));
  gp_Mat Hop;
  GProp::HOperator(g,loc,dim,Hop);
  inertia = inertia+Hop;
}

void GProp_VelGProps::Perform(const gp_Sphere&    S,
			      const Standard_Real Teta1,
			      const Standard_Real Teta2,
			      const Standard_Real Alpha1,
			      const Standard_Real Alpha2)
{
  Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
  S.Location().Coord(X0,Y0,Z0);
  S.Position().XDirection().Coord(Xa1,Ya1,Za1);
  S.Position().YDirection().Coord(Xa2,Ya2,Za2);
  S.Position().Direction().Coord(Xa3,Ya3,Za3);
  Standard_Real R = S.Radius();
  Standard_Real Cnt1 = Cos(Teta1);
  Standard_Real Snt1 = Sin(Teta1);
  Standard_Real Cnt2 = Cos(Teta2);
  Standard_Real Snt2 = Sin(Teta2);
  Standard_Real Cnf1 = Cos(Alpha1);
  Standard_Real Snf1 = Sin(Alpha1);
  Standard_Real Cnf2 = Cos(Alpha2);
  Standard_Real Snf2 = Sin(Alpha2);
   
  dim = (Teta2-Teta1)*R*R*R*(Snf2-Snf1)/3.;   

  Standard_Real Ix = 
    R*(Snt2-Snt1)/(Teta2-Teta1)*
    (Alpha2-Alpha1+Snf2*Cnf2-Snf1*Cnf1)/(Snf2-Snf1)/2.;
  Standard_Real Iy = 
    R*(Cnt1-Cnt2)/(Teta2-Teta1)*
    (Alpha2-Alpha1+Snf2*Cnf2-Snf1*Cnf1)/(Snf2-Snf1)/2.;
  Standard_Real Iz = R*(Snf2+Snf1)/2.;
  g.SetCoord(
   X0 + Ix*Xa1 + Iy*Xa2 + Iz*Xa3,
   Y0 + Ix*Ya1 + Iy*Ya2 + Iz*Ya3,
   Z0 + Ix*Za1 + Iy*Za2 + Iz*Za3);

  Standard_Real IR2 = ( Cnf2*Snf2*(Cnf2+1.)- Cnf1*Snf1*(Cnf1+1.) +
                       Alpha2-Alpha1 )/9.;
  Standard_Real ICn2 = (Teta2-Teta1+ Cnt2*Snt2-Cnt1*Snt1)*IR2/2.;
  Standard_Real ISn2 = (Teta2-Teta1-Cnt2*Snt2+Cnt1*Snt1)*IR2/2.;
  Standard_Real ICnSn = ( Snt2*Snt2-Snt1*Snt1)*IR2/2.;
  Standard_Real IZ2 = (Teta2-Teta1)*(Snf2*Snf2*Snf2-Snf1*Snf1*Snf1)/9.;
  Standard_Real ICnz =(Snt2-Snt1)*(Cnf1*Cnf1*Cnf1-Cnf2*Cnf2*Cnf2)/9.;
  Standard_Real ISnz =(Cnt1-Cnt2)*(Cnf1*Cnf1*Cnf1-Cnf2*Cnf2*Cnf2)/9.;

  math_Matrix Dm(1,3,1,3);
  Dm(1,1) = ISn2 +IZ2; 
  Dm(2,2) = ICn2 +IZ2;
  Dm(3,3) = IR2*(Teta2-Teta1);
  Dm(1,2) = Dm(2,1) = -ICnSn;
  Dm(1,3) = Dm(3,1) = -ICnz;
  Dm(3,2) = Dm(2,3) = -ISnz;

  math_Matrix Passage (1,3,1,3);
  Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
  Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
  Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;

  math_Jacobi J(Dm);
  R = R*R*R*R*R;
  math_Vector V1(1,3), V2(1,3), V3(1,3);
  J.Vector(1,V1);
  V1.Multiply(Passage,V1);
  V1.Multiply(R*J.Value(1));
  J.Vector(2,V2);
  V2.Multiply(Passage,V2);
  V2.Multiply(R*J.Value(2));
  J.Vector(3,V3);
  V3.Multiply(Passage,V3);
  V3.Multiply(R*J.Value(3));

  inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
		    gp_XYZ(V1(2),V2(2),V3(2)),
		    gp_XYZ(V1(3),V2(3),V3(3)));
  gp_Mat Hop;
  GProp::HOperator(g,loc,dim,Hop);
  inertia = inertia+Hop;

}


void GProp_VelGProps::Perform(const gp_Torus&    S,
			      const Standard_Real Teta1,
			      const Standard_Real Teta2,
			      const Standard_Real Alpha1,
			      const Standard_Real Alpha2)
{
  Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
  S.Location().Coord(X0,Y0,Z0);
  S.Position().XDirection().Coord(Xa1,Ya1,Za1);
  S.Position().YDirection().Coord(Xa2,Ya2,Za2);
  S.Position().Direction().Coord(Xa3,Ya3,Za3);
  Standard_Real RMax = S.MajorRadius();
  Standard_Real Rmin = S.MinorRadius();
  Standard_Real Cnt1 = Cos(Teta1);
  Standard_Real Snt1 = Sin(Teta1);
  Standard_Real Cnt2 = Cos(Alpha2);
  Standard_Real Snt2 = Sin(Alpha2);
  Standard_Real Cnf1 = Cos(Alpha1);
  Standard_Real Snf1 = Sin(Alpha1);
  Standard_Real Cnf2 = Cos(Alpha2);
  Standard_Real Snf2 = Sin(Alpha2);

  dim = RMax*Rmin*Rmin*(Teta2-Teta1)*(Alpha2-Alpha1)/2.;
  Standard_Real Ix = 
    (Snt2-Snt1)/(Teta2-Teta1)*(Rmin*(Snf2-Snf1)/(Alpha2-Alpha1) + RMax);
  Standard_Real Iy = 
    (Cnt1-Cnt2)/(Teta2-Teta1)*(Rmin*(Snf2-Snf1)/(Alpha2-Alpha1) + RMax);
  Standard_Real Iz = Rmin*(Cnf1-Cnf2)/(Alpha2-Alpha1);
  
  g.SetCoord(
	     X0+Ix*Xa1+Iy*Xa2+Iz*Xa3,
	     Y0+Ix*Ya1+Iy*Ya2+Iz*Ya3,
	     Z0+Ix*Za1+Iy*Za2+Iz*Za3);

  Standard_Real IR2 =  RMax*RMax+Rmin*Rmin/2. +2.*RMax*Rmin*(Snf2-Snf1) +
   		       Rmin*Rmin/2.*(Snf2*Cnf2-Snf1*Cnf1);
  Standard_Real ICn2 = IR2*(Teta2-Teta1 +Snt2*Cnt2-Snt1*Cnt1)/2.;
  Standard_Real ISn2 = IR2*(Teta2-Teta1 -Snt2*Cnt2+Snt1*Cnt1)/2.;
  Standard_Real ICnSn = IR2*(Snt2*Snt2-Snt1*Snt1)/2.;
  Standard_Real IZ2 = 
     (Teta2-Teta1)*Rmin*Rmin*(Alpha2-Alpha1-Snf2*Cnf2+Snf1*Cnf1)/2.;
  Standard_Real ICnz = Rmin*(Snt2-Snt1)*(Cnf1-Cnf2)*(RMax+Rmin*(Cnf1+Cnf2)/2.);
  Standard_Real ISnz = Rmin*(Cnt2-Cnt1)*(Cnf1-Cnf2)*(RMax+Rmin*(Cnf1+Cnf2)/2.);

  math_Matrix Dm(1,3,1,3);
  Dm(1,1) = ISn2 + IZ2; 
  Dm(2,2) = ICn2 + IZ2;
  Dm(3,3) = IR2*(Teta2-Teta1);
  Dm(1,2) = Dm(2,1) = -ICnSn;
  Dm(1,3) = Dm(3,1) = -ICnz;
  Dm(3,2) = Dm(2,3) = -ISnz;

  math_Matrix Passage (1,3,1,3);
  Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
  Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
  Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;

  math_Jacobi J(Dm);
  RMax = RMax*Rmin*Rmin/2.;
  math_Vector V1(1,3), V2(1,3), V3(1,3);
  J.Vector(1,V1);
  V1.Multiply(Passage,V1);
  V1.Multiply(RMax*J.Value(1));
  J.Vector(2,V2);
  V2.Multiply(Passage,V2);
  V2.Multiply(RMax*J.Value(2));
  J.Vector(3,V3);
  V3.Multiply(Passage,V3);
  V3.Multiply(RMax*J.Value(3));

  inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
		    gp_XYZ(V1(2),V2(2),V3(2)),
		    gp_XYZ(V1(3),V2(3),V3(3)));
  gp_Mat Hop;
  GProp::HOperator(g,loc,dim,Hop);
  inertia = inertia+Hop;
}