7fd59977 |
1 | // File gp_Vec.lxx , JCV 03/06/90 |
2 | // Modif JCV 07/12/90 introduction classe XYZ dans le package gp |
3 | // LPA et JCV 07/92 mise a jour |
4 | |
5 | #include <gp.hxx> |
6 | #include <gp_Dir.hxx> |
7 | #include <gp_Pnt.hxx> |
8 | #include <gp_Trsf.hxx> |
9 | #include <gp_VectorWithNullMagnitude.hxx> |
10 | #include <Standard_ConstructionError.hxx> |
11 | |
12 | inline gp_Vec::gp_Vec() { } |
13 | |
14 | inline gp_Vec::gp_Vec (const gp_Dir& V) { coord = V.XYZ(); } |
15 | |
16 | inline gp_Vec::gp_Vec (const gp_XYZ& Coord) : coord(Coord) { } |
17 | |
18 | inline gp_Vec::gp_Vec (const Standard_Real Xv, |
19 | const Standard_Real Yv, |
20 | const Standard_Real Zv) |
21 | : coord (Xv, Yv, Zv) { } |
22 | |
23 | inline gp_Vec::gp_Vec (const gp_Pnt& P1, |
24 | const gp_Pnt& P2) |
25 | { coord = P2.XYZ().Subtracted(P1.XYZ()); } |
26 | |
27 | inline void gp_Vec::SetCoord (const Standard_Integer Index, |
28 | const Standard_Real Xi) |
29 | { coord.SetCoord (Index, Xi); } |
30 | |
31 | inline void gp_Vec::SetCoord (const Standard_Real Xv, |
32 | const Standard_Real Yv, |
33 | const Standard_Real Zv) |
34 | { |
35 | coord.SetX(Xv); |
36 | coord.SetY(Yv); |
37 | coord.SetZ(Zv); |
38 | } |
39 | |
40 | inline void gp_Vec::SetX (const Standard_Real X) |
41 | { coord.SetX (X); } |
42 | |
43 | inline void gp_Vec::SetY (const Standard_Real Y) |
44 | { coord.SetY (Y); } |
45 | |
46 | inline void gp_Vec::SetZ (const Standard_Real Z) |
47 | { coord.SetZ (Z); } |
48 | |
49 | inline void gp_Vec::SetXYZ (const gp_XYZ& Coord) |
50 | { coord = Coord; } |
51 | |
52 | inline Standard_Real gp_Vec::Coord (const Standard_Integer Index) const |
53 | { return coord.Coord (Index); } |
54 | |
55 | inline void gp_Vec::Coord(Standard_Real& Xv, |
56 | Standard_Real& Yv, |
57 | Standard_Real& Zv) const |
58 | { |
59 | Xv = coord.X(); |
60 | Yv = coord.Y(); |
61 | Zv = coord.Z(); |
62 | } |
63 | |
64 | inline Standard_Real gp_Vec::X() const |
65 | { return coord.X(); } |
66 | |
67 | inline Standard_Real gp_Vec::Y() const |
68 | { return coord.Y(); } |
69 | |
70 | inline Standard_Real gp_Vec::Z() const |
71 | { return coord.Z(); } |
72 | |
73 | inline const gp_XYZ& gp_Vec::XYZ () const |
74 | { return coord; } |
75 | |
76 | inline Standard_Boolean gp_Vec::IsNormal |
77 | (const gp_Vec& Other, |
78 | const Standard_Real AngularTolerance) const |
79 | { |
c6541a0c |
80 | Standard_Real Ang = M_PI / 2.0 - Angle(Other); |
7fd59977 |
81 | if (Ang < 0) Ang = - Ang; |
82 | return Ang <= AngularTolerance; |
83 | } |
84 | |
85 | inline Standard_Boolean gp_Vec::IsOpposite |
86 | (const gp_Vec& Other, |
87 | const Standard_Real AngularTolerance) const |
88 | { |
c6541a0c |
89 | Standard_Real Ang = M_PI - Angle(Other); |
7fd59977 |
90 | return Ang <= AngularTolerance; |
91 | } |
92 | |
93 | inline Standard_Boolean gp_Vec::IsParallel |
94 | (const gp_Vec& Other, |
95 | const Standard_Real AngularTolerance) const |
96 | { |
97 | Standard_Real Ang = Angle (Other); |
c6541a0c |
98 | return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance; |
7fd59977 |
99 | } |
100 | |
101 | inline Standard_Real gp_Vec::Angle (const gp_Vec& Other) const |
102 | { |
103 | // Commentaires : |
104 | // Au dessus de 45 degres l'arccos donne la meilleur precision pour le |
105 | // calcul de l'angle. Sinon il vaut mieux utiliser l'arcsin. |
106 | // Les erreurs commises sont loin d'etre negligeables lorsque l'on est |
107 | // proche de zero ou de 90 degres. |
108 | // En 3d les valeurs angulaires sont toujours positives et comprises entre |
109 | // 0 et Pi. |
110 | |
111 | gp_VectorWithNullMagnitude_Raise_if |
112 | (coord.Modulus() <= gp::Resolution() || |
113 | Other.coord.Modulus() <= gp::Resolution(), " "); |
114 | return (gp_Dir(coord)).Angle(Other); |
115 | } |
116 | |
117 | inline Standard_Real gp_Vec::AngleWithRef (const gp_Vec& Other, |
118 | const gp_Vec& Vref) const |
119 | { |
120 | gp_VectorWithNullMagnitude_Raise_if |
121 | (coord.Modulus() <= gp::Resolution() || |
122 | Vref.coord.Modulus () <= gp::Resolution() || |
123 | Other.coord.Modulus() <= gp::Resolution(), " "); |
124 | return (gp_Dir(coord)).AngleWithRef(Other,Vref); |
125 | } |
126 | |
127 | inline Standard_Real gp_Vec::Magnitude() const |
128 | { return coord.Modulus(); } |
129 | |
130 | inline Standard_Real gp_Vec::SquareMagnitude() const |
131 | { return coord.SquareModulus(); } |
132 | |
133 | inline void gp_Vec::Add (const gp_Vec& Other) |
134 | { coord.Add (Other.coord); } |
135 | |
136 | inline gp_Vec gp_Vec::Added (const gp_Vec& Other) const |
137 | { |
138 | gp_Vec V = *this; |
139 | V.coord.Add (Other.coord); |
140 | return V; |
141 | } |
142 | |
143 | inline void gp_Vec::Subtract (const gp_Vec& Right) |
144 | { coord.Subtract (Right.coord); } |
145 | |
146 | inline gp_Vec gp_Vec::Subtracted (const gp_Vec& Right) const |
147 | { |
148 | gp_Vec V = *this; |
149 | V.coord.Subtract(Right.coord); |
150 | return V; |
151 | } |
152 | |
153 | inline void gp_Vec::Multiply (const Standard_Real Scalar) |
154 | { coord.Multiply(Scalar); } |
155 | |
156 | inline gp_Vec gp_Vec::Multiplied (const Standard_Real Scalar) const |
157 | { |
158 | gp_Vec V = *this; |
159 | V.coord.Multiply (Scalar); |
160 | return V; |
161 | } |
162 | |
163 | inline void gp_Vec::Divide (const Standard_Real Scalar) |
164 | { coord.Divide (Scalar); } |
165 | |
166 | inline gp_Vec gp_Vec::Divided (const Standard_Real Scalar) const |
167 | { |
168 | gp_Vec V = *this; |
169 | V.coord.Divide (Scalar); |
170 | return V; |
171 | } |
172 | |
173 | inline void gp_Vec::Cross (const gp_Vec& Right) |
174 | { coord.Cross (Right.coord); } |
175 | |
176 | inline gp_Vec gp_Vec::Crossed (const gp_Vec& Right) const |
177 | { |
178 | gp_Vec V = *this; |
179 | V.coord.Cross (Right.coord); |
180 | return V; |
181 | } |
182 | |
183 | inline Standard_Real gp_Vec::CrossMagnitude |
184 | (const gp_Vec& Right) const |
185 | { return coord.CrossMagnitude (Right.coord); } |
186 | |
187 | inline Standard_Real gp_Vec::CrossSquareMagnitude |
188 | (const gp_Vec& Right) const |
189 | { return coord.CrossSquareMagnitude (Right.coord); } |
190 | |
191 | inline void gp_Vec::CrossCross (const gp_Vec& V1, |
192 | const gp_Vec& V2) |
193 | { coord.CrossCross(V1.coord, V2.coord); } |
194 | |
195 | inline gp_Vec gp_Vec::CrossCrossed (const gp_Vec& V1, |
196 | const gp_Vec& V2) const |
197 | { |
198 | gp_Vec V = *this; |
199 | V.coord.CrossCross(V1.coord, V2.coord); |
200 | return V; |
201 | } |
202 | |
203 | inline Standard_Real gp_Vec::Dot (const gp_Vec& Other) const |
204 | { return coord.Dot (Other.coord); } |
205 | |
206 | inline Standard_Real gp_Vec::DotCross (const gp_Vec& V1, |
207 | const gp_Vec& V2) const |
208 | { return coord.DotCross (V1.coord, V2.coord); } |
209 | |
210 | inline void gp_Vec::Normalize() |
211 | { |
212 | Standard_Real D = coord.Modulus(); |
213 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
214 | coord.Divide (D); |
215 | } |
216 | |
217 | inline gp_Vec gp_Vec::Normalized() const |
218 | { |
219 | Standard_Real D = coord.Modulus(); |
220 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
221 | gp_Vec V = *this; |
222 | V.coord.Divide (D); |
223 | return V; |
224 | } |
225 | |
226 | inline void gp_Vec::Reverse() |
227 | { coord.Reverse(); } |
228 | |
229 | inline gp_Vec gp_Vec::Reversed () const |
230 | { |
231 | gp_Vec V = *this; |
232 | V.coord.Reverse(); |
233 | return V; |
234 | } |
235 | |
236 | inline void gp_Vec::SetLinearForm |
237 | (const Standard_Real L, |
238 | const gp_Vec& Left, |
239 | const Standard_Real R, |
240 | const gp_Vec& Right) |
241 | { coord.SetLinearForm (L, Left.coord, R, Right.coord); } |
242 | |
243 | inline void gp_Vec::SetLinearForm |
244 | (const Standard_Real L, |
245 | const gp_Vec& Left, |
246 | const gp_Vec& Right) |
247 | { coord.SetLinearForm (L, Left.coord, Right.coord); } |
248 | |
249 | inline void gp_Vec::SetLinearForm |
250 | (const gp_Vec& Left, |
251 | const gp_Vec& Right) |
252 | { coord.SetLinearForm (Left.coord, Right.coord); } |
253 | |
254 | inline void gp_Vec::SetLinearForm |
255 | (const Standard_Real A1, const gp_Vec& V1, |
256 | const Standard_Real A2, const gp_Vec& V2, |
257 | const Standard_Real A3, const gp_Vec& V3) |
258 | { coord.SetLinearForm (A1, V1.coord, A2, V2.coord, A3, V3.coord); } |
259 | |
260 | inline void gp_Vec::SetLinearForm |
261 | (const Standard_Real A1, const gp_Vec& V1, |
262 | const Standard_Real A2, const gp_Vec& V2, |
263 | const gp_Vec& V3) |
264 | { coord.SetLinearForm (A1, V1.coord, A2, V2.coord, V3.coord); } |
265 | |
266 | inline void gp_Vec::SetLinearForm |
267 | (const Standard_Real A1, const gp_Vec& V1, |
268 | const Standard_Real A2, const gp_Vec& V2, |
269 | const Standard_Real A3, const gp_Vec& V3, |
270 | const gp_Vec& V4) |
271 | { coord.SetLinearForm(A1,V1.coord,A2,V2.coord,A3,V3.coord,V4.coord); } |
272 | |
273 | inline void gp_Vec::Rotate (const gp_Ax1& A1, |
274 | const Standard_Real Ang) |
275 | { |
276 | gp_Trsf T; |
277 | T.SetRotation (A1, Ang); |
278 | coord.Multiply (T.VectorialPart()); |
279 | } |
280 | |
281 | inline gp_Vec gp_Vec::Rotated (const gp_Ax1& A1, |
282 | const Standard_Real Ang) const |
283 | { |
284 | gp_Vec Vres = *this; |
285 | Vres.Rotate (A1, Ang); |
286 | return Vres; |
287 | } |
288 | |
289 | inline void gp_Vec::Scale (const Standard_Real S) |
290 | { coord.Multiply (S); } |
291 | |
292 | inline gp_Vec gp_Vec::Scaled (const Standard_Real S) const |
293 | { |
294 | gp_Vec V = *this; |
295 | V.coord.Multiply(S); |
296 | return V; |
297 | } |
298 | |
299 | inline gp_Vec gp_Vec::Transformed (const gp_Trsf& T) const |
300 | { |
301 | gp_Vec V = *this; |
302 | V.Transform(T); |
303 | return V; |
304 | } |
305 | |
306 | inline gp_Vec operator* (const Standard_Real Scalar, const gp_Vec& V) { |
307 | return V.Multiplied(Scalar); |
308 | } |
309 | |