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
|
#include <GProp_GProps.ixx>
#include <GProp.hxx>
#include <math_Jacobi.hxx>
#include <gp.hxx>
#include <gp.hxx>
#include <gp_XYZ.hxx>
#include <gp_Vec.hxx>
GProp_GProps::GProp_GProps () : g (gp::Origin()) , loc (gp::Origin()), dim (0.0)
{
inertia = gp_Mat(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
}
GProp_GProps::GProp_GProps (const gp_Pnt& SystemLocation) :
g (gp::Origin()), loc (SystemLocation), dim (0.0)
{
inertia = gp_Mat(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
}
void GProp_GProps::Add (const GProp_GProps& Item, const Standard_Real Density) {
if (Density <= gp::Resolution()) Standard_DomainError::Raise();
if (loc.Distance (Item.loc) <= gp::Resolution ()) {
gp_XYZ GXYZ = (Item.g.XYZ()).Multiplied (Item.dim * Density);
g.SetXYZ (g.XYZ().Multiplied (dim));
GXYZ.Add (g.XYZ());
dim = dim + Item.dim * Density;
if (Abs(dim) >= 1.e-20 ) {
GXYZ.Divide (dim);
g.SetXYZ (GXYZ);
}
else {
g.SetCoord(0., 0., 0.);
}
inertia = inertia + Item.inertia * Density;
}else{
gp_XYZ Itemloc = loc.XYZ() - Item.loc.XYZ();
gp_XYZ Itemg = Item.loc.XYZ() + Item.g.XYZ();
gp_XYZ GXYZ = Item.g.XYZ() - Itemloc;
GXYZ = GXYZ.Multiplied (Item.dim * Density);
g.SetXYZ (g.XYZ().Multiplied (dim));
GXYZ.Add (g.XYZ());
dim = dim + Item.dim * Density;
if (Abs(dim) >= 1.e-20 ) {
GXYZ.Divide (dim);
g.SetXYZ (GXYZ);
}
else {
g.SetCoord(0., 0., 0.);
}
//We have to compute the inertia of the Item at the location point
//of the system using the Huyghens theorem
gp_Mat HMat;
gp_Mat ItemInertia = Item.inertia;
if (Item.g.XYZ().Modulus() > gp::Resolution()) {
//Computes the inertia of Item at its dim centre
GProp::HOperator (Itemg, Item.loc, Item.dim, HMat);
ItemInertia = ItemInertia - HMat;
}
//Computes the inertia of Item at the location point of the system
GProp::HOperator (Itemg, loc, Item.dim, HMat);
ItemInertia = ItemInertia + HMat;
inertia = inertia + ItemInertia * Density;
}
}
Standard_Real GProp_GProps::Mass () const { return dim; }
gp_Pnt GProp_GProps::CentreOfMass () const
{
return gp_Pnt(loc.XYZ() + g.XYZ());
}
gp_Mat GProp_GProps::MatrixOfInertia () const {
gp_Mat HMat;
GProp::HOperator (g,gp::Origin(),dim, HMat);
return inertia - HMat;
}
void GProp_GProps::StaticMoments (Standard_Real& Ix,
Standard_Real& Iy,
Standard_Real& Iz) const {
gp_XYZ G = loc.XYZ() + g.XYZ();
Ix = G.X() * dim;
Iy = G.Y() * dim;
Iz = G.Z() * dim;
}
Standard_Real GProp_GProps::MomentOfInertia (const gp_Ax1& A) const {
// Moment of inertia / axis A
// 1] computes the math_Matrix of inertia / A.location()
// 2] applies this math_Matrix to A.Direction()
// 3] then computes the scalar product between this vector and
// A.Direction()
if (loc.Distance (A.Location()) <= gp::Resolution()) {
return (A.Direction().XYZ()).Dot (
(A.Direction().XYZ()).Multiplied (inertia));
}
else {
gp_Mat HMat;
gp_Mat AxisInertia = MatrixOfInertia();
GProp::HOperator (gp_Pnt (loc.XYZ() + g.XYZ()), A.Location(), dim, HMat);
AxisInertia = AxisInertia + HMat;
return (A.Direction().XYZ()).Dot (
(A.Direction().XYZ()).Multiplied (AxisInertia));
}
}
Standard_Real GProp_GProps::RadiusOfGyration (const gp_Ax1& A) const {
return Sqrt (MomentOfInertia (A) / dim);
}
GProp_PrincipalProps GProp_GProps::PrincipalProperties () const {
math_Matrix DiagMat (1, 3, 1, 3);
Standard_Integer i, j;
gp_Mat AxisInertia = MatrixOfInertia();
for (j = 1; j <= 3; j++) {
for (i = 1; i <= 3; i++) {
DiagMat (i, j) = AxisInertia.Value (i, j);
}
}
math_Jacobi J (DiagMat);
Standard_Real Ixx = J.Value (1);
Standard_Real Iyy = J.Value (2);
Standard_Real Izz = J.Value (3);
DiagMat = J.Vectors ();
gp_Vec Vxx (DiagMat (1,1), DiagMat (2, 1), DiagMat (3, 1));
gp_Vec Vyy (DiagMat (1,2), DiagMat (2, 2), DiagMat (3, 2));
gp_Vec Vzz (DiagMat (1,3), DiagMat (2, 3), DiagMat (3, 3));
//
// protection contre dim == 0.0e0 au cas ou on aurait rentre qu'un point
//
Standard_Real Rxx = 0.0e0 ;
Standard_Real Ryy = 0.0e0 ;
Standard_Real Rzz = 0.0e0 ;
if (0.0e0 != dim) {
Rxx = Sqrt (Abs(Ixx / dim));
Ryy = Sqrt (Abs(Iyy / dim));
Rzz = Sqrt (Abs(Izz / dim));
}
return GProp_PrincipalProps (Ixx, Iyy, Izz, Rxx, Ryy, Rzz, Vxx, Vyy, Vzz,
gp_Pnt(g.XYZ() + loc.XYZ()));
}
|