1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <gp_Cone.hxx>
17 #include <gp_Cylinder.hxx>
19 #include <gp_Sphere.hxx>
20 #include <gp_Torus.hxx>
22 #include <GProp_VelGProps.hxx>
23 #include <math_Jacobi.hxx>
24 #include <math_Matrix.hxx>
25 #include <math_Vector.hxx>
27 GProp_VelGProps::GProp_VelGProps(){}
29 void GProp_VelGProps::SetLocation(const gp_Pnt& VLocation)
35 GProp_VelGProps::GProp_VelGProps(const gp_Cylinder& S,
36 const Standard_Real Alpha1,
37 const Standard_Real Alpha2,
38 const Standard_Real Z1,
39 const Standard_Real Z2,
40 const gp_Pnt& VLocation)
42 SetLocation(VLocation);
43 Perform(S,Alpha1,Alpha2,Z1,Z2);
46 GProp_VelGProps::GProp_VelGProps(const gp_Cone& S,
47 const Standard_Real Alpha1,
48 const Standard_Real Alpha2,
49 const Standard_Real Z1,
50 const Standard_Real Z2,
51 const gp_Pnt& VLocation)
53 SetLocation(VLocation);
54 Perform(S,Alpha1,Alpha2,Z1,Z2);
57 GProp_VelGProps::GProp_VelGProps(const gp_Sphere& S,
58 const Standard_Real Teta1,
59 const Standard_Real Teta2,
60 const Standard_Real Alpha1,
61 const Standard_Real Alpha2,
62 const gp_Pnt& VLocation)
64 SetLocation(VLocation);
65 Perform(S,Teta1,Teta2,Alpha1,Alpha2);
69 GProp_VelGProps::GProp_VelGProps(const gp_Torus& S,
70 const Standard_Real Teta1,
71 const Standard_Real Teta2,
72 const Standard_Real Alpha1,
73 const Standard_Real Alpha2,
74 const gp_Pnt& VLocation)
76 SetLocation(VLocation);
77 Perform(S,Teta1,Teta2,Alpha1,Alpha2);
80 void GProp_VelGProps::Perform(const gp_Cylinder& S,
81 const Standard_Real Alpha1,
82 const Standard_Real Alpha2,
83 const Standard_Real Z1,
84 const Standard_Real Z2)
86 Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
87 S.Location().Coord(X0,Y0,Z0);
88 Standard_Real Rayon = S.Radius();
89 S.Position().XDirection().Coord(Xa1,Ya1,Za1);
90 S.Position().YDirection().Coord(Xa2,Ya2,Za2);
91 S.Position().Direction().Coord(Xa3,Ya3,Za3);
92 dim = Rayon*Rayon*(Z2-Z1)/2.;
93 Standard_Real SA2 = Sin(Alpha2);
94 Standard_Real SA1 = Sin(Alpha1);
95 Standard_Real CA2 = Cos(Alpha2);
96 Standard_Real CA1 = Cos(Alpha1);
97 Standard_Real Dsin = SA2-SA1;
98 Standard_Real Dcos = CA1-CA2;
99 Standard_Real Coef = Rayon/(Alpha2-Alpha1);
101 g.SetCoord(X0+(Coef*(Xa1*Dsin+Xa2*Dcos) ) + (Xa3*(Z2+Z1)/2.),
102 Y0+(Coef*(Ya1*Dsin+Ya2*Dcos) ) + (Ya3*(Z2+Z1)/2.),
103 Z0+(Coef*(Za1*Dsin+Za2*Dcos) ) + (Za3*(Z2+Z1)/2.) );
105 Standard_Real ICn2 = dim/2. *( Alpha2-Alpha1 + SA2*CA2 - SA1*CA1 );
106 Standard_Real ISn2 = dim/2. *( Alpha2-Alpha1 - SA2*CA2 + SA1*CA1 );
107 Standard_Real IZ2 = dim * (Alpha2-Alpha1)*(Z2*Z2+Z1*Z2+Z1*Z1);
108 Standard_Real ICnSn = dim *(CA2*CA2-CA1*CA1)/2.;
109 Standard_Real ICnz = dim *(Z2+Z1)/2.*Dsin;
110 Standard_Real ISnz = dim *(Z2+Z1)/2.*Dcos;
111 dim =(Alpha2-Alpha1)*dim;
113 math_Matrix Dm(1,3,1,3);
115 Dm(1,1) = Rayon*Rayon*ISn2 + IZ2;
116 Dm(2,2) = Rayon*Rayon*ICn2 + IZ2;
117 Dm(3,3) = Rayon*Rayon*dim;
118 Dm(1,2) = Dm(2,1) = -Rayon*Rayon*ICnSn;
119 Dm(1,3) = Dm(3,1) = -Rayon*ICnz;
120 Dm(3,2) = Dm(2,3) = -Rayon*ISnz;
122 math_Matrix Passage (1,3,1,3);
123 Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
124 Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
125 Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;
128 math_Vector V1(1,3),V2(1,3),V3(1,3);
130 V1.Multiply(Passage,V1);
131 V1.Multiply(J.Value(1));
133 V2.Multiply(Passage,V2);
134 V2.Multiply(J.Value(2));
136 V3.Multiply(Passage,V3);
137 V3.Multiply(J.Value(3));
139 inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
140 gp_XYZ(V1(2),V2(2),V3(2)),
141 gp_XYZ(V1(3),V2(3),V3(3)));
143 GProp::HOperator(g,loc,dim,Hop);
144 inertia = inertia+Hop;
147 void GProp_VelGProps::Perform(const gp_Cone& S,
148 const Standard_Real Alpha1,
149 const Standard_Real Alpha2,
150 const Standard_Real Z1,
151 const Standard_Real Z2)
153 Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
154 S.Location().Coord(X0,Y0,Z0);
155 S.Position().XDirection().Coord(Xa1,Ya1,Za1);
156 S.Position().YDirection().Coord(Xa2,Ya2,Za2);
157 S.Position().Direction().Coord(Xa3,Ya3,Za3);
158 Standard_Real t =S.SemiAngle();
159 Standard_Real Cnt = Cos(t);
160 Standard_Real Snt = Sin(t);
161 Standard_Real R = S.RefRadius();
162 Standard_Real Sn2 = Sin(Alpha2);
163 Standard_Real Sn1 = Sin(Alpha1);
164 Standard_Real Cn2 = Cos(Alpha2);
165 Standard_Real Cn1 = Cos(Alpha1);
166 Standard_Real ZZ = (Z2-Z1)*(Z2-Z1)*Cnt*Snt;
167 Standard_Real Auxi1= 2*R +(Z2+Z1)*Snt;
169 dim = ZZ*(Alpha2-Alpha1)*Auxi1/2.;
171 Standard_Real R1 = R + Z1*Snt;
172 Standard_Real R2 = R + Z2*Snt;
173 Standard_Real Coef0 = (R1*R1+R1*R2+R2*R2);
174 Standard_Real Iz = Cnt*(R*(Z2+Z1) + 2*Snt*(Z1*Z1+Z1*Z2+Z2*Z2)/3.)/Auxi1;
175 Standard_Real Ix = Coef0*(Sn2-Sn1)/(Alpha2-Alpha1)/Auxi1;
176 Standard_Real Iy = Coef0*(Cn1-Cn2)/(Alpha2-Alpha1)/Auxi1;
178 g.SetCoord(X0 + Xa1*Ix + Xa2*Iy + Xa3*Iz,
179 Y0 + Ya1*Ix + Ya2*Iy + Ya3*Iz,
180 Z0 + Za1*Ix + Za2*Iy + Za3*Iz);
182 Standard_Real IR2 = ZZ*(R2*R2*R2+R2*R2*R1+R1*R1*R2+R1*R1*R1)/4.;
183 Standard_Real ICn2 = IR2*(Alpha2-Alpha1+Cn2*Sn2-Cn1*Sn1)/2.;
184 Standard_Real ISn2 = IR2*(Alpha2-Alpha1+Cn2*Sn2-Cn1*Sn1)/2.;
185 Standard_Real IZ2 = ZZ*Cnt*Cnt*(Alpha2-Alpha1)*
186 (Z1*Z1*(R/3 + Z1*Snt/4) +
187 Z2*Z2*(R/3 + Z2*Snt/4) +
188 Z1*Z2*(R/3 +Z1*Snt/4 +Z2*Snt/4));
189 Standard_Real ICnSn = IR2*(Cn2*Cn2-Cn1*Cn1);
190 Standard_Real ICnz = (Z1+Z2)*ZZ*Coef0*(Sn2-Sn1)/3;
191 Standard_Real ISnz = (Z1+Z2)*ZZ*Coef0*(Cn1-Cn2)/3;
194 math_Matrix Dm(1,3,1,3);
195 Dm(1,1) = ISn2 + IZ2;
196 Dm(2,2) = ICn2 + IZ2;
197 Dm(3,3) = IR2*(Alpha2-Alpha1);
198 Dm(1,2) = Dm(2,1) = -ICnSn;
199 Dm(1,3) = Dm(3,1) = -ICnz;
200 Dm(3,2) = Dm(2,3) = -ISnz;
202 math_Matrix Passage (1,3,1,3);
203 Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
204 Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
205 Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;
208 math_Vector V1(1,3),V2(1,3),V3(1,3);
210 V1.Multiply(Passage,V1);
211 V1.Multiply(J.Value(1));
213 V2.Multiply(Passage,V2);
214 V2.Multiply(J.Value(2));
216 V3.Multiply(Passage,V3);
217 V3.Multiply(J.Value(3));
219 inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
220 gp_XYZ(V1(2),V2(2),V3(2)),
221 gp_XYZ(V1(3),V2(3),V3(3)));
223 GProp::HOperator(g,loc,dim,Hop);
224 inertia = inertia+Hop;
227 void GProp_VelGProps::Perform(const gp_Sphere& S,
228 const Standard_Real Teta1,
229 const Standard_Real Teta2,
230 const Standard_Real Alpha1,
231 const Standard_Real Alpha2)
233 Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
234 S.Location().Coord(X0,Y0,Z0);
235 S.Position().XDirection().Coord(Xa1,Ya1,Za1);
236 S.Position().YDirection().Coord(Xa2,Ya2,Za2);
237 S.Position().Direction().Coord(Xa3,Ya3,Za3);
238 Standard_Real R = S.Radius();
239 Standard_Real Cnt1 = Cos(Teta1);
240 Standard_Real Snt1 = Sin(Teta1);
241 Standard_Real Cnt2 = Cos(Teta2);
242 Standard_Real Snt2 = Sin(Teta2);
243 Standard_Real Cnf1 = Cos(Alpha1);
244 Standard_Real Snf1 = Sin(Alpha1);
245 Standard_Real Cnf2 = Cos(Alpha2);
246 Standard_Real Snf2 = Sin(Alpha2);
248 dim = (Teta2-Teta1)*R*R*R*(Snf2-Snf1)/3.;
251 R*(Snt2-Snt1)/(Teta2-Teta1)*
252 (Alpha2-Alpha1+Snf2*Cnf2-Snf1*Cnf1)/(Snf2-Snf1)/2.;
254 R*(Cnt1-Cnt2)/(Teta2-Teta1)*
255 (Alpha2-Alpha1+Snf2*Cnf2-Snf1*Cnf1)/(Snf2-Snf1)/2.;
256 Standard_Real Iz = R*(Snf2+Snf1)/2.;
258 X0 + Ix*Xa1 + Iy*Xa2 + Iz*Xa3,
259 Y0 + Ix*Ya1 + Iy*Ya2 + Iz*Ya3,
260 Z0 + Ix*Za1 + Iy*Za2 + Iz*Za3);
262 Standard_Real IR2 = ( Cnf2*Snf2*(Cnf2+1.)- Cnf1*Snf1*(Cnf1+1.) +
264 Standard_Real ICn2 = (Teta2-Teta1+ Cnt2*Snt2-Cnt1*Snt1)*IR2/2.;
265 Standard_Real ISn2 = (Teta2-Teta1-Cnt2*Snt2+Cnt1*Snt1)*IR2/2.;
266 Standard_Real ICnSn = ( Snt2*Snt2-Snt1*Snt1)*IR2/2.;
267 Standard_Real IZ2 = (Teta2-Teta1)*(Snf2*Snf2*Snf2-Snf1*Snf1*Snf1)/9.;
268 Standard_Real ICnz =(Snt2-Snt1)*(Cnf1*Cnf1*Cnf1-Cnf2*Cnf2*Cnf2)/9.;
269 Standard_Real ISnz =(Cnt1-Cnt2)*(Cnf1*Cnf1*Cnf1-Cnf2*Cnf2*Cnf2)/9.;
271 math_Matrix Dm(1,3,1,3);
274 Dm(3,3) = IR2*(Teta2-Teta1);
275 Dm(1,2) = Dm(2,1) = -ICnSn;
276 Dm(1,3) = Dm(3,1) = -ICnz;
277 Dm(3,2) = Dm(2,3) = -ISnz;
279 math_Matrix Passage (1,3,1,3);
280 Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
281 Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
282 Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;
286 math_Vector V1(1,3), V2(1,3), V3(1,3);
288 V1.Multiply(Passage,V1);
289 V1.Multiply(R*J.Value(1));
291 V2.Multiply(Passage,V2);
292 V2.Multiply(R*J.Value(2));
294 V3.Multiply(Passage,V3);
295 V3.Multiply(R*J.Value(3));
297 inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
298 gp_XYZ(V1(2),V2(2),V3(2)),
299 gp_XYZ(V1(3),V2(3),V3(3)));
301 GProp::HOperator(g,loc,dim,Hop);
302 inertia = inertia+Hop;
307 void GProp_VelGProps::Perform(const gp_Torus& S,
308 const Standard_Real Teta1,
309 const Standard_Real Teta2,
310 const Standard_Real Alpha1,
311 const Standard_Real Alpha2)
313 Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
314 S.Location().Coord(X0,Y0,Z0);
315 S.Position().XDirection().Coord(Xa1,Ya1,Za1);
316 S.Position().YDirection().Coord(Xa2,Ya2,Za2);
317 S.Position().Direction().Coord(Xa3,Ya3,Za3);
318 Standard_Real RMax = S.MajorRadius();
319 Standard_Real Rmin = S.MinorRadius();
320 Standard_Real Cnt1 = Cos(Teta1);
321 Standard_Real Snt1 = Sin(Teta1);
322 Standard_Real Cnt2 = Cos(Alpha2);
323 Standard_Real Snt2 = Sin(Alpha2);
324 Standard_Real Cnf1 = Cos(Alpha1);
325 Standard_Real Snf1 = Sin(Alpha1);
326 Standard_Real Cnf2 = Cos(Alpha2);
327 Standard_Real Snf2 = Sin(Alpha2);
329 dim = RMax*Rmin*Rmin*(Teta2-Teta1)*(Alpha2-Alpha1)/2.;
331 (Snt2-Snt1)/(Teta2-Teta1)*(Rmin*(Snf2-Snf1)/(Alpha2-Alpha1) + RMax);
333 (Cnt1-Cnt2)/(Teta2-Teta1)*(Rmin*(Snf2-Snf1)/(Alpha2-Alpha1) + RMax);
334 Standard_Real Iz = Rmin*(Cnf1-Cnf2)/(Alpha2-Alpha1);
337 X0+Ix*Xa1+Iy*Xa2+Iz*Xa3,
338 Y0+Ix*Ya1+Iy*Ya2+Iz*Ya3,
339 Z0+Ix*Za1+Iy*Za2+Iz*Za3);
341 Standard_Real IR2 = RMax*RMax+Rmin*Rmin/2. +2.*RMax*Rmin*(Snf2-Snf1) +
342 Rmin*Rmin/2.*(Snf2*Cnf2-Snf1*Cnf1);
343 Standard_Real ICn2 = IR2*(Teta2-Teta1 +Snt2*Cnt2-Snt1*Cnt1)/2.;
344 Standard_Real ISn2 = IR2*(Teta2-Teta1 -Snt2*Cnt2+Snt1*Cnt1)/2.;
345 Standard_Real ICnSn = IR2*(Snt2*Snt2-Snt1*Snt1)/2.;
347 (Teta2-Teta1)*Rmin*Rmin*(Alpha2-Alpha1-Snf2*Cnf2+Snf1*Cnf1)/2.;
348 Standard_Real ICnz = Rmin*(Snt2-Snt1)*(Cnf1-Cnf2)*(RMax+Rmin*(Cnf1+Cnf2)/2.);
349 Standard_Real ISnz = Rmin*(Cnt2-Cnt1)*(Cnf1-Cnf2)*(RMax+Rmin*(Cnf1+Cnf2)/2.);
351 math_Matrix Dm(1,3,1,3);
352 Dm(1,1) = ISn2 + IZ2;
353 Dm(2,2) = ICn2 + IZ2;
354 Dm(3,3) = IR2*(Teta2-Teta1);
355 Dm(1,2) = Dm(2,1) = -ICnSn;
356 Dm(1,3) = Dm(3,1) = -ICnz;
357 Dm(3,2) = Dm(2,3) = -ISnz;
359 math_Matrix Passage (1,3,1,3);
360 Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
361 Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
362 Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;
365 RMax = RMax*Rmin*Rmin/2.;
366 math_Vector V1(1,3), V2(1,3), V3(1,3);
368 V1.Multiply(Passage,V1);
369 V1.Multiply(RMax*J.Value(1));
371 V2.Multiply(Passage,V2);
372 V2.Multiply(RMax*J.Value(2));
374 V3.Multiply(Passage,V3);
375 V3.Multiply(RMax*J.Value(3));
377 inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
378 gp_XYZ(V1(2),V2(2),V3(2)),
379 gp_XYZ(V1(3),V2(3),V3(3)));
381 GProp::HOperator(g,loc,dim,Hop);
382 inertia = inertia+Hop;