Commit | Line | Data |
---|---|---|
42cf5bc1 | 1 | // Copyright (c) 1991-1999 Matra Datavision |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS | |
3 | // | |
4 | // This file is part of Open CASCADE Technology software library. | |
5 | // | |
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. | |
11 | // | |
12 | // Alternatively, this file may be used under the terms of Open CASCADE | |
13 | // commercial license or contractual agreement. | |
14 | ||
15 | #ifndef _gp_Dir_HeaderFile | |
16 | #define _gp_Dir_HeaderFile | |
17 | ||
18 | #include <Standard.hxx> | |
19 | #include <Standard_DefineAlloc.hxx> | |
20 | #include <Standard_Handle.hxx> | |
21 | ||
22 | #include <gp_XYZ.hxx> | |
23 | #include <Standard_Real.hxx> | |
24 | #include <Standard_Integer.hxx> | |
25 | #include <Standard_Boolean.hxx> | |
26 | class Standard_ConstructionError; | |
27 | class Standard_DomainError; | |
28 | class Standard_OutOfRange; | |
29 | class gp_Vec; | |
30 | class gp_XYZ; | |
31 | class gp_Ax1; | |
32 | class gp_Ax2; | |
33 | class gp_Trsf; | |
34 | ||
35 | ||
36 | ||
37 | //! Describes a unit vector in 3D space. This unit vector is also called "Direction". | |
38 | //! See Also | |
39 | //! gce_MakeDir which provides functions for more complex | |
40 | //! unit vector constructions | |
41 | //! Geom_Direction which provides additional functions for | |
42 | //! constructing unit vectors and works, in particular, with the | |
43 | //! parametric equations of unit vectors. | |
44 | class gp_Dir | |
45 | { | |
46 | public: | |
47 | ||
48 | DEFINE_STANDARD_ALLOC | |
49 | ||
50 | ||
51 | //! Creates a direction corresponding to X axis. | |
52 | gp_Dir(); | |
53 | ||
54 | //! Normalizes the vector V and creates a direction. Raises ConstructionError if V.Magnitude() <= Resolution. | |
55 | gp_Dir(const gp_Vec& V); | |
56 | ||
57 | //! Creates a direction from a triplet of coordinates. Raises ConstructionError if Coord.Modulus() <= Resolution from gp. | |
58 | gp_Dir(const gp_XYZ& Coord); | |
59 | ||
60 | //! Creates a direction with its 3 cartesian coordinates. Raises ConstructionError if Sqrt(Xv*Xv + Yv*Yv + Zv*Zv) <= Resolution | |
61 | //! Modification of the direction's coordinates | |
62 | //! If Sqrt (X*X + Y*Y + Z*Z) <= Resolution from gp where | |
63 | //! X, Y ,Z are the new coordinates it is not possible to | |
64 | //! construct the direction and the method raises the | |
65 | //! exception ConstructionError. | |
66 | gp_Dir(const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv); | |
67 | ||
68 | ||
69 | //! For this unit vector, assigns the value Xi to: | |
70 | //! - the X coordinate if Index is 1, or | |
71 | //! - the Y coordinate if Index is 2, or | |
72 | //! - the Z coordinate if Index is 3, | |
73 | //! and then normalizes it. | |
74 | //! Warning | |
75 | //! Remember that all the coordinates of a unit vector are | |
76 | //! implicitly modified when any single one is changed directly. | |
77 | //! Exceptions | |
78 | //! Standard_OutOfRange if Index is not 1, 2, or 3. | |
79 | //! Standard_ConstructionError if either of the following | |
80 | //! is less than or equal to gp::Resolution(): | |
81 | //! - Sqrt(Xv*Xv + Yv*Yv + Zv*Zv), or | |
82 | //! - the modulus of the number triple formed by the new | |
83 | //! value Xi and the two other coordinates of this vector | |
84 | //! that were not directly modified. | |
85 | void SetCoord (const Standard_Integer Index, const Standard_Real Xi); | |
86 | ||
87 | //! For this unit vector, assigns the values Xv, Yv and Zv to its three coordinates. | |
88 | //! Remember that all the coordinates of a unit vector are | |
89 | //! implicitly modified when any single one is changed directly. | |
90 | void SetCoord (const Standard_Real Xv, const Standard_Real Yv, const Standard_Real Zv); | |
91 | ||
92 | //! Assigns the given value to the X coordinate of this unit vector. | |
93 | void SetX (const Standard_Real X); | |
94 | ||
95 | //! Assigns the given value to the Y coordinate of this unit vector. | |
96 | void SetY (const Standard_Real Y); | |
97 | ||
98 | //! Assigns the given value to the Z coordinate of this unit vector. | |
99 | void SetZ (const Standard_Real Z); | |
100 | ||
101 | //! Assigns the three coordinates of Coord to this unit vector. | |
102 | void SetXYZ (const gp_XYZ& Coord); | |
103 | ||
104 | ||
105 | //! Returns the coordinate of range Index : | |
106 | //! Index = 1 => X is returned | |
107 | //! Index = 2 => Y is returned | |
108 | //! Index = 3 => Z is returned | |
109 | //! Exceptions | |
110 | //! Standard_OutOfRange if Index is not 1, 2, or 3. | |
111 | Standard_Real Coord (const Standard_Integer Index) const; | |
112 | ||
113 | //! Returns for the unit vector its three coordinates Xv, Yv, and Zv. | |
114 | void Coord (Standard_Real& Xv, Standard_Real& Yv, Standard_Real& Zv) const; | |
115 | ||
116 | //! Returns the X coordinate for a unit vector. | |
117 | Standard_Real X() const; | |
118 | ||
119 | //! Returns the Y coordinate for a unit vector. | |
120 | Standard_Real Y() const; | |
121 | ||
122 | //! Returns the Z coordinate for a unit vector. | |
123 | Standard_Real Z() const; | |
124 | ||
125 | //! for this unit vector, returns its three coordinates as a number triplea. | |
126 | const gp_XYZ& XYZ() const; | |
127 | ||
128 | ||
129 | //! Returns True if the angle between the two directions is | |
130 | //! lower or equal to AngularTolerance. | |
131 | Standard_Boolean IsEqual (const gp_Dir& Other, const Standard_Real AngularTolerance) const; | |
132 | ||
133 | ||
134 | //! Returns True if the angle between this unit vector and the unit vector Other is equal to Pi/2 (normal). | |
135 | Standard_Boolean IsNormal (const gp_Dir& Other, const Standard_Real AngularTolerance) const; | |
136 | ||
137 | ||
138 | //! Returns True if the angle between this unit vector and the unit vector Other is equal to Pi (opposite). | |
139 | Standard_Boolean IsOpposite (const gp_Dir& Other, const Standard_Real AngularTolerance) const; | |
140 | ||
141 | ||
142 | //! Returns true if the angle between this unit vector and the | |
143 | //! unit vector Other is equal to 0 or to Pi. | |
144 | //! Note: the tolerance criterion is given by AngularTolerance. | |
145 | Standard_Boolean IsParallel (const gp_Dir& Other, const Standard_Real AngularTolerance) const; | |
146 | ||
147 | ||
148 | //! Computes the angular value in radians between <me> and | |
149 | //! <Other>. This value is always positive in 3D space. | |
150 | //! Returns the angle in the range [0, PI] | |
151 | Standard_EXPORT Standard_Real Angle (const gp_Dir& Other) const; | |
152 | ||
153 | ||
154 | //! Computes the angular value between <me> and <Other>. | |
155 | //! <VRef> is the direction of reference normal to <me> and <Other> | |
156 | //! and its orientation gives the positive sense of rotation. | |
157 | //! If the cross product <me> ^ <Other> has the same orientation | |
158 | //! as <VRef> the angular value is positive else negative. | |
159 | //! Returns the angular value in the range -PI and PI (in radians). Raises DomainError if <me> and <Other> are not parallel this exception is raised | |
160 | //! when <VRef> is in the same plane as <me> and <Other> | |
161 | //! The tolerance criterion is Resolution from package gp. | |
162 | Standard_EXPORT Standard_Real AngleWithRef (const gp_Dir& Other, const gp_Dir& VRef) const; | |
163 | ||
164 | //! Computes the cross product between two directions | |
165 | //! Raises the exception ConstructionError if the two directions | |
166 | //! are parallel because the computed vector cannot be normalized | |
167 | //! to create a direction. | |
168 | void Cross (const gp_Dir& Right); | |
169 | void operator ^= (const gp_Dir& Right) | |
170 | { | |
171 | Cross(Right); | |
172 | } | |
173 | ||
174 | //! Computes the triple vector product. | |
175 | //! <me> ^ (V1 ^ V2) | |
176 | //! Raises the exception ConstructionError if V1 and V2 are parallel | |
177 | //! or <me> and (V1^V2) are parallel because the computed vector | |
178 | //! can't be normalized to create a direction. | |
0be7dbe1 BB |
179 | Standard_NODISCARD gp_Dir Crossed (const gp_Dir& Right) const; |
180 | Standard_NODISCARD gp_Dir operator ^ (const gp_Dir& Right) const | |
42cf5bc1 | 181 | { |
182 | return Crossed(Right); | |
183 | } | |
184 | ||
185 | void CrossCross (const gp_Dir& V1, const gp_Dir& V2); | |
186 | ||
187 | //! Computes the double vector product this ^ (V1 ^ V2). | |
188 | //! - CrossCrossed creates a new unit vector. | |
189 | //! Exceptions | |
190 | //! Standard_ConstructionError if: | |
191 | //! - V1 and V2 are parallel, or | |
192 | //! - this unit vector and (V1 ^ V2) are parallel. | |
193 | //! This is because, in these conditions, the computed vector | |
194 | //! is null and cannot be normalized. | |
0be7dbe1 | 195 | Standard_NODISCARD gp_Dir CrossCrossed (const gp_Dir& V1, const gp_Dir& V2) const; |
42cf5bc1 | 196 | |
197 | //! Computes the scalar product | |
198 | Standard_Real Dot (const gp_Dir& Other) const; | |
199 | Standard_Real operator * (const gp_Dir& Other) const | |
200 | { | |
201 | return Dot(Other); | |
202 | } | |
203 | ||
204 | ||
205 | //! Computes the triple scalar product <me> * (V1 ^ V2). | |
206 | //! Warnings : | |
207 | //! The computed vector V1' = V1 ^ V2 is not normalized | |
208 | //! to create a unitary vector. So this method never | |
209 | //! raises an exception even if V1 and V2 are parallel. | |
210 | Standard_Real DotCross (const gp_Dir& V1, const gp_Dir& V2) const; | |
211 | ||
212 | void Reverse(); | |
213 | ||
214 | //! Reverses the orientation of a direction | |
215 | //! geometric transformations | |
216 | //! Performs the symmetrical transformation of a direction | |
217 | //! with respect to the direction V which is the center of | |
218 | //! the symmetry.] | |
0be7dbe1 BB |
219 | Standard_NODISCARD gp_Dir Reversed() const; |
220 | Standard_NODISCARD gp_Dir operator -() const | |
42cf5bc1 | 221 | { |
222 | return Reversed(); | |
223 | } | |
224 | ||
225 | Standard_EXPORT void Mirror (const gp_Dir& V); | |
226 | ||
227 | ||
228 | //! Performs the symmetrical transformation of a direction | |
229 | //! with respect to the direction V which is the center of | |
230 | //! the symmetry. | |
6ed44b1c | 231 | Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Dir& V) const; |
42cf5bc1 | 232 | |
233 | Standard_EXPORT void Mirror (const gp_Ax1& A1); | |
234 | ||
235 | ||
236 | //! Performs the symmetrical transformation of a direction | |
237 | //! with respect to an axis placement which is the axis | |
238 | //! of the symmetry. | |
6ed44b1c | 239 | Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Ax1& A1) const; |
42cf5bc1 | 240 | |
241 | Standard_EXPORT void Mirror (const gp_Ax2& A2); | |
242 | ||
243 | ||
244 | //! Performs the symmetrical transformation of a direction | |
245 | //! with respect to a plane. The axis placement A2 locates | |
246 | //! the plane of the symmetry : (Location, XDirection, YDirection). | |
6ed44b1c | 247 | Standard_NODISCARD Standard_EXPORT gp_Dir Mirrored (const gp_Ax2& A2) const; |
42cf5bc1 | 248 | |
249 | void Rotate (const gp_Ax1& A1, const Standard_Real Ang); | |
250 | ||
251 | ||
252 | //! Rotates a direction. A1 is the axis of the rotation. | |
253 | //! Ang is the angular value of the rotation in radians. | |
0be7dbe1 | 254 | Standard_NODISCARD gp_Dir Rotated (const gp_Ax1& A1, const Standard_Real Ang) const; |
42cf5bc1 | 255 | |
256 | Standard_EXPORT void Transform (const gp_Trsf& T); | |
257 | ||
258 | ||
259 | //! Transforms a direction with a "Trsf" from gp. | |
260 | //! Warnings : | |
261 | //! If the scale factor of the "Trsf" T is negative then the | |
262 | //! direction <me> is reversed. | |
0be7dbe1 | 263 | Standard_NODISCARD gp_Dir Transformed (const gp_Trsf& T) const; |
42cf5bc1 | 264 | |
265 | ||
bc73b006 | 266 | //! Dumps the content of me into the stream |
267 | Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; | |
268 | ||
6b63dc83 | 269 | //! Inits the content of me from the stream |
270 | Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); | |
42cf5bc1 | 271 | |
272 | ||
273 | protected: | |
274 | ||
275 | ||
276 | ||
277 | ||
278 | ||
279 | private: | |
280 | ||
281 | ||
282 | ||
283 | gp_XYZ coord; | |
284 | ||
285 | ||
286 | }; | |
287 | ||
288 | ||
289 | #include <gp_Dir.lxx> | |
290 | ||
291 | ||
292 | ||
293 | ||
294 | ||
295 | #endif // _gp_Dir_HeaderFile |