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_Vec2d_HeaderFile | |
16 | #define _gp_Vec2d_HeaderFile | |
17 | ||
18 | #include <Standard.hxx> | |
19 | #include <Standard_DefineAlloc.hxx> | |
20 | #include <Standard_Handle.hxx> | |
21 | ||
22 | #include <gp_XY.hxx> | |
23 | #include <Standard_Real.hxx> | |
24 | #include <Standard_Integer.hxx> | |
25 | #include <Standard_Boolean.hxx> | |
26 | class Standard_ConstructionError; | |
27 | class Standard_OutOfRange; | |
28 | class gp_VectorWithNullMagnitude; | |
29 | class gp_Dir2d; | |
30 | class gp_XY; | |
31 | class gp_Pnt2d; | |
32 | class gp_Ax2d; | |
33 | class gp_Trsf2d; | |
34 | ||
35 | ||
36 | ||
37 | //! Defines a non-persistent vector in 2D space. | |
38 | class gp_Vec2d | |
39 | { | |
40 | public: | |
41 | ||
42 | DEFINE_STANDARD_ALLOC | |
43 | ||
44 | ||
45 | //! Creates a zero vector. | |
46 | gp_Vec2d(); | |
47 | ||
48 | //! Creates a unitary vector from a direction V. | |
49 | gp_Vec2d(const gp_Dir2d& V); | |
50 | ||
51 | //! Creates a vector with a doublet of coordinates. | |
52 | gp_Vec2d(const gp_XY& Coord); | |
53 | ||
54 | //! Creates a point with its two Cartesian coordinates. | |
55 | gp_Vec2d(const Standard_Real Xv, const Standard_Real Yv); | |
56 | ||
57 | ||
58 | //! Creates a vector from two points. The length of the vector | |
59 | //! is the distance between P1 and P2 | |
60 | gp_Vec2d(const gp_Pnt2d& P1, const gp_Pnt2d& P2); | |
61 | ||
62 | //! Changes the coordinate of range Index | |
63 | //! Index = 1 => X is modified | |
64 | //! Index = 2 => Y is modified | |
65 | //! Raises OutOfRange if Index != {1, 2}. | |
66 | void SetCoord (const Standard_Integer Index, const Standard_Real Xi); | |
67 | ||
68 | //! For this vector, assigns | |
69 | //! the values Xv and Yv to its two coordinates | |
70 | void SetCoord (const Standard_Real Xv, const Standard_Real Yv); | |
71 | ||
72 | //! Assigns the given value to the X coordinate of this vector. | |
73 | void SetX (const Standard_Real X); | |
74 | ||
75 | //! Assigns the given value to the Y coordinate of this vector. | |
76 | void SetY (const Standard_Real Y); | |
77 | ||
78 | //! Assigns the two coordinates of Coord to this vector. | |
79 | void SetXY (const gp_XY& Coord); | |
80 | ||
81 | ||
82 | //! Returns the coordinate of range Index : | |
83 | //! Index = 1 => X is returned | |
84 | //! Index = 2 => Y is returned | |
85 | //! Raised if Index != {1, 2}. | |
86 | Standard_Real Coord (const Standard_Integer Index) const; | |
87 | ||
88 | //! For this vector, returns its two coordinates Xv and Yv | |
89 | void Coord (Standard_Real& Xv, Standard_Real& Yv) const; | |
90 | ||
91 | //! For this vector, returns its X coordinate. | |
92 | Standard_Real X() const; | |
93 | ||
94 | //! For this vector, returns its Y coordinate. | |
95 | Standard_Real Y() const; | |
96 | ||
97 | //! For this vector, returns its two coordinates as a number pair | |
98 | const gp_XY& XY() const; | |
99 | ||
100 | ||
101 | //! Returns True if the two vectors have the same magnitude value | |
102 | //! and the same direction. The precision values are LinearTolerance | |
103 | //! for the magnitude and AngularTolerance for the direction. | |
104 | Standard_EXPORT Standard_Boolean IsEqual (const gp_Vec2d& Other, const Standard_Real LinearTolerance, const Standard_Real AngularTolerance) const; | |
105 | ||
106 | ||
107 | //! Returns True if abs(Abs(<me>.Angle(Other)) - PI/2.) | |
108 | //! <= AngularTolerance | |
109 | //! Raises VectorWithNullMagnitude if <me>.Magnitude() <= Resolution or | |
110 | //! Other.Magnitude() <= Resolution from gp. | |
111 | Standard_Boolean IsNormal (const gp_Vec2d& Other, const Standard_Real AngularTolerance) const; | |
112 | ||
113 | ||
114 | //! Returns True if PI - Abs(<me>.Angle(Other)) <= AngularTolerance | |
115 | //! Raises VectorWithNullMagnitude if <me>.Magnitude() <= Resolution or | |
116 | //! Other.Magnitude() <= Resolution from gp. | |
d0fcf95a | 117 | Standard_Boolean IsOpposite (const gp_Vec2d& Other, const Standard_Real AngularTolerance) const; |
42cf5bc1 | 118 | |
119 | ||
120 | //! Returns true if Abs(Angle(<me>, Other)) <= AngularTolerance or | |
121 | //! PI - Abs(Angle(<me>, Other)) <= AngularTolerance | |
122 | //! Two vectors with opposite directions are considered as parallel. | |
123 | //! Raises VectorWithNullMagnitude if <me>.Magnitude() <= Resolution or | |
124 | //! Other.Magnitude() <= Resolution from gp | |
d0fcf95a | 125 | Standard_Boolean IsParallel (const gp_Vec2d& Other, const Standard_Real AngularTolerance) const; |
42cf5bc1 | 126 | |
127 | ||
128 | //! Computes the angular value between <me> and <Other> | |
129 | //! returns the angle value between -PI and PI in radian. | |
130 | //! The orientation is from <me> to Other. The positive sense is the | |
131 | //! trigonometric sense. | |
132 | //! Raises VectorWithNullMagnitude if <me>.Magnitude() <= Resolution from gp or | |
133 | //! Other.Magnitude() <= Resolution because the angular value is | |
134 | //! indefinite if one of the vectors has a null magnitude. | |
135 | Standard_EXPORT Standard_Real Angle (const gp_Vec2d& Other) const; | |
136 | ||
137 | //! Computes the magnitude of this vector. | |
138 | Standard_Real Magnitude() const; | |
139 | ||
140 | //! Computes the square magnitude of this vector. | |
141 | Standard_Real SquareMagnitude() const; | |
142 | ||
143 | void Add (const gp_Vec2d& Other); | |
d0fcf95a | 144 | void operator += (const gp_Vec2d& Other) |
145 | { | |
146 | Add(Other); | |
147 | } | |
42cf5bc1 | 148 | |
149 | //! Adds two vectors | |
0be7dbe1 BB |
150 | Standard_NODISCARD gp_Vec2d Added (const gp_Vec2d& Other) const; |
151 | Standard_NODISCARD gp_Vec2d operator + (const gp_Vec2d& Other) const | |
d0fcf95a | 152 | { |
153 | return Added(Other); | |
154 | } | |
42cf5bc1 | 155 | |
156 | //! Computes the crossing product between two vectors | |
0be7dbe1 BB |
157 | Standard_NODISCARD Standard_Real Crossed (const gp_Vec2d& Right) const; |
158 | Standard_NODISCARD Standard_Real operator ^ (const gp_Vec2d& Right) const | |
d0fcf95a | 159 | { |
160 | return Crossed(Right); | |
161 | } | |
42cf5bc1 | 162 | |
163 | ||
164 | //! Computes the magnitude of the cross product between <me> and | |
165 | //! Right. Returns || <me> ^ Right || | |
166 | Standard_Real CrossMagnitude (const gp_Vec2d& Right) const; | |
167 | ||
168 | ||
169 | //! Computes the square magnitude of the cross product between <me> and | |
170 | //! Right. Returns || <me> ^ Right ||**2 | |
171 | Standard_Real CrossSquareMagnitude (const gp_Vec2d& Right) const; | |
172 | ||
173 | void Divide (const Standard_Real Scalar); | |
d0fcf95a | 174 | void operator /= (const Standard_Real Scalar) |
175 | { | |
176 | Divide(Scalar); | |
177 | } | |
42cf5bc1 | 178 | |
179 | //! divides a vector by a scalar | |
0be7dbe1 BB |
180 | Standard_NODISCARD gp_Vec2d Divided (const Standard_Real Scalar) const; |
181 | Standard_NODISCARD gp_Vec2d operator / (const Standard_Real Scalar) const | |
d0fcf95a | 182 | { |
183 | return Divided(Scalar); | |
184 | } | |
42cf5bc1 | 185 | |
186 | //! Computes the scalar product | |
187 | Standard_Real Dot (const gp_Vec2d& Other) const; | |
d0fcf95a | 188 | Standard_Real operator * (const gp_Vec2d& Other) const |
189 | { | |
190 | return Dot(Other); | |
191 | } | |
192 | ||
42cf5bc1 | 193 | gp_Vec2d GetNormal() const; |
194 | ||
195 | void Multiply (const Standard_Real Scalar); | |
d0fcf95a | 196 | void operator *= (const Standard_Real Scalar) |
197 | { | |
198 | Multiply(Scalar); | |
199 | } | |
42cf5bc1 | 200 | |
201 | //! Normalizes a vector | |
202 | //! Raises an exception if the magnitude of the vector is | |
203 | //! lower or equal to Resolution from package gp. | |
0be7dbe1 BB |
204 | Standard_NODISCARD gp_Vec2d Multiplied (const Standard_Real Scalar) const; |
205 | Standard_NODISCARD gp_Vec2d operator * (const Standard_Real Scalar) const | |
d0fcf95a | 206 | { |
207 | return Multiplied(Scalar); | |
208 | } | |
42cf5bc1 | 209 | |
210 | void Normalize(); | |
211 | ||
212 | //! Normalizes a vector | |
213 | //! Raises an exception if the magnitude of the vector is | |
214 | //! lower or equal to Resolution from package gp. | |
215 | //! Reverses the direction of a vector | |
0be7dbe1 | 216 | Standard_NODISCARD gp_Vec2d Normalized() const; |
42cf5bc1 | 217 | |
218 | void Reverse(); | |
219 | ||
220 | //! Reverses the direction of a vector | |
0be7dbe1 BB |
221 | Standard_NODISCARD gp_Vec2d Reversed() const; |
222 | Standard_NODISCARD gp_Vec2d operator -() const | |
d0fcf95a | 223 | { |
224 | return Reversed(); | |
225 | } | |
42cf5bc1 | 226 | |
227 | //! Subtracts two vectors | |
228 | void Subtract (const gp_Vec2d& Right); | |
d0fcf95a | 229 | void operator -= (const gp_Vec2d& Right) |
230 | { | |
231 | Subtract(Right); | |
232 | } | |
42cf5bc1 | 233 | |
234 | //! Subtracts two vectors | |
0be7dbe1 BB |
235 | Standard_NODISCARD gp_Vec2d Subtracted (const gp_Vec2d& Right) const; |
236 | Standard_NODISCARD gp_Vec2d operator - (const gp_Vec2d& Right) const | |
d0fcf95a | 237 | { |
238 | return Subtracted(Right); | |
239 | } | |
42cf5bc1 | 240 | |
241 | ||
242 | //! <me> is set to the following linear form : | |
243 | //! A1 * V1 + A2 * V2 + V3 | |
244 | void SetLinearForm (const Standard_Real A1, const gp_Vec2d& V1, const Standard_Real A2, const gp_Vec2d& V2, const gp_Vec2d& V3); | |
245 | ||
246 | ||
247 | //! <me> is set to the following linear form : A1 * V1 + A2 * V2 | |
248 | void SetLinearForm (const Standard_Real A1, const gp_Vec2d& V1, const Standard_Real A2, const gp_Vec2d& V2); | |
249 | ||
250 | ||
251 | //! <me> is set to the following linear form : A1 * V1 + V2 | |
252 | void SetLinearForm (const Standard_Real A1, const gp_Vec2d& V1, const gp_Vec2d& V2); | |
253 | ||
254 | ||
255 | //! <me> is set to the following linear form : Left + Right | |
256 | void SetLinearForm (const gp_Vec2d& Left, const gp_Vec2d& Right); | |
257 | ||
258 | ||
259 | //! Performs the symmetrical transformation of a vector | |
260 | //! with respect to the vector V which is the center of | |
261 | //! the symmetry. | |
262 | Standard_EXPORT void Mirror (const gp_Vec2d& V); | |
263 | ||
264 | ||
265 | //! Performs the symmetrical transformation of a vector | |
266 | //! with respect to the vector V which is the center of | |
267 | //! the symmetry. | |
6ed44b1c | 268 | Standard_NODISCARD Standard_EXPORT gp_Vec2d Mirrored (const gp_Vec2d& V) const; |
42cf5bc1 | 269 | |
270 | ||
271 | //! Performs the symmetrical transformation of a vector | |
272 | //! with respect to an axis placement which is the axis | |
273 | //! of the symmetry. | |
274 | Standard_EXPORT void Mirror (const gp_Ax2d& A1); | |
275 | ||
276 | ||
277 | //! Performs the symmetrical transformation of a vector | |
278 | //! with respect to an axis placement which is the axis | |
279 | //! of the symmetry. | |
6ed44b1c | 280 | Standard_NODISCARD Standard_EXPORT gp_Vec2d Mirrored (const gp_Ax2d& A1) const; |
42cf5bc1 | 281 | |
282 | void Rotate (const Standard_Real Ang); | |
283 | ||
284 | ||
285 | //! Rotates a vector. Ang is the angular value of the | |
286 | //! rotation in radians. | |
0be7dbe1 | 287 | Standard_NODISCARD gp_Vec2d Rotated (const Standard_Real Ang) const; |
42cf5bc1 | 288 | |
289 | void Scale (const Standard_Real S); | |
290 | ||
291 | //! Scales a vector. S is the scaling value. | |
0be7dbe1 | 292 | Standard_NODISCARD gp_Vec2d Scaled (const Standard_Real S) const; |
42cf5bc1 | 293 | |
294 | Standard_EXPORT void Transform (const gp_Trsf2d& T); | |
295 | ||
296 | //! Transforms a vector with a Trsf from gp. | |
0be7dbe1 | 297 | Standard_NODISCARD gp_Vec2d Transformed (const gp_Trsf2d& T) const; |
42cf5bc1 | 298 | |
299 | ||
300 | ||
301 | ||
302 | protected: | |
303 | ||
304 | ||
305 | ||
306 | ||
307 | ||
308 | private: | |
309 | ||
310 | ||
311 | ||
312 | gp_XY coord; | |
313 | ||
314 | ||
315 | }; | |
316 | ||
317 | ||
318 | #include <gp_Vec2d.lxx> | |
319 | ||
320 | ||
321 | ||
322 | ||
323 | ||
324 | #endif // _gp_Vec2d_HeaderFile |