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