0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / gp / gp_XYZ.hxx
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_XYZ_HeaderFile
16 #define _gp_XYZ_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <Standard_Real.hxx>
23 #include <Standard_Integer.hxx>
24 #include <Standard_Boolean.hxx>
25 class Standard_ConstructionError;
26 class Standard_OutOfRange;
27 class gp_Mat;
28
29
30
31 //! This class describes a cartesian coordinate entity in
32 //! 3D space {X,Y,Z}. This entity is used for algebraic
33 //! calculation. This entity can be transformed
34 //! with a "Trsf" or a  "GTrsf" from package "gp".
35 //! It is used in vectorial computations or for holding this type
36 //! of information in data structures.
37 class gp_XYZ 
38 {
39 public:
40
41   DEFINE_STANDARD_ALLOC
42
43   
44   //! Creates an XYZ object with zero co-ordinates (0,0,0)
45     gp_XYZ();
46   
47   //! creates an XYZ with given coordinates
48     gp_XYZ(const Standard_Real X, const Standard_Real Y, const Standard_Real Z);
49   
50   //! For this XYZ object, assigns
51   //! the values X, Y and Z to its three coordinates
52     void SetCoord (const Standard_Real X, const Standard_Real Y, const Standard_Real Z);
53   
54
55   //! modifies the coordinate of range Index
56   //! Index = 1 => X is modified
57   //! Index = 2 => Y is modified
58   //! Index = 3 => Z is modified
59   //! Raises OutOfRange if Index != {1, 2, 3}.
60     void SetCoord (const Standard_Integer Index, const Standard_Real Xi);
61   
62   //! Assigns the given value to the X coordinate
63     void SetX (const Standard_Real X);
64   
65   //! Assigns the given value to the Y coordinate
66     void SetY (const Standard_Real Y);
67   
68   //! Assigns the given value to the Z coordinate
69     void SetZ (const Standard_Real Z);
70   
71
72   //! returns the coordinate of range Index :
73   //! Index = 1 => X is returned
74   //! Index = 2 => Y is returned
75   //! Index = 3 => Z is returned
76   //!
77   //! Raises OutOfRange if Index != {1, 2, 3}.
78     Standard_Real Coord (const Standard_Integer Index) const;
79   
80     Standard_Real& ChangeCoord (const Standard_Integer theIndex);
81   
82     void Coord (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const;
83
84     //! Returns a const ptr to coordinates location.
85     //! Is useful for algorithms, but DOES NOT PERFORM
86     //! ANY CHECKS!
87     inline const Standard_Real* GetData() const { return (&x); }
88
89     //! Returns a ptr to coordinates location.
90     //! Is useful for algorithms, but DOES NOT PERFORM
91     //! ANY CHECKS!
92     inline Standard_Real* ChangeData() { return (&x); }
93   
94   //! Returns the X coordinate
95     Standard_Real X() const;
96   
97   //! Returns the Y coordinate
98     Standard_Real Y() const;
99   
100   //! Returns the Z coordinate
101     Standard_Real Z() const;
102   
103   //! computes Sqrt (X*X + Y*Y + Z*Z) where X, Y and Z are the three coordinates of this XYZ object.
104     Standard_Real Modulus() const;
105   
106   //! Computes X*X + Y*Y + Z*Z where X, Y and Z are the three coordinates of this XYZ object.
107     Standard_Real SquareModulus() const;
108   
109
110   //! Returns True if he coordinates of this XYZ object are
111   //! equal to the respective coordinates Other,
112   //! within the specified tolerance Tolerance. I.e.:
113   //! abs(<me>.X() - Other.X()) <= Tolerance and
114   //! abs(<me>.Y() - Other.Y()) <= Tolerance and
115   //! abs(<me>.Z() - Other.Z()) <= Tolerance.
116   Standard_EXPORT Standard_Boolean IsEqual (const gp_XYZ& Other, const Standard_Real Tolerance) const;
117   
118
119   //! <me>.X() = <me>.X() + Other.X()
120   //! <me>.Y() = <me>.Y() + Other.Y()
121   //! <me>.Z() = <me>.Z() + Other.Z()
122     void Add (const gp_XYZ& Other);
123   void operator += (const gp_XYZ& Other)
124 {
125   Add(Other);
126 }
127   
128
129   //! new.X() = <me>.X() + Other.X()
130   //! new.Y() = <me>.Y() + Other.Y()
131   //! new.Z() = <me>.Z() + Other.Z()
132     gp_XYZ Added (const gp_XYZ& Other) const;
133   gp_XYZ operator + (const gp_XYZ& Other) const
134 {
135   return Added(Other);
136 }
137   
138
139   //! <me>.X() = <me>.Y() * Other.Z() - <me>.Z() * Other.Y()
140   //! <me>.Y() = <me>.Z() * Other.X() - <me>.X() * Other.Z()
141   //! <me>.Z() = <me>.X() * Other.Y() - <me>.Y() * Other.X()
142     void Cross (const gp_XYZ& Right);
143   void operator ^= (const gp_XYZ& Right)
144 {
145   Cross(Right);
146 }
147   
148
149   //! new.X() = <me>.Y() * Other.Z() - <me>.Z() * Other.Y()
150   //! new.Y() = <me>.Z() * Other.X() - <me>.X() * Other.Z()
151   //! new.Z() = <me>.X() * Other.Y() - <me>.Y() * Other.X()
152     gp_XYZ Crossed (const gp_XYZ& Right) const;
153   gp_XYZ operator ^ (const gp_XYZ& Right) const
154 {
155   return Crossed(Right);
156 }
157   
158
159   //! Computes the magnitude of the cross product between <me> and
160   //! Right. Returns || <me> ^ Right ||
161     Standard_Real CrossMagnitude (const gp_XYZ& Right) const;
162   
163
164   //! Computes the square magnitude of the cross product between <me> and
165   //! Right. Returns || <me> ^ Right ||**2
166     Standard_Real CrossSquareMagnitude (const gp_XYZ& Right) const;
167   
168   //! Triple vector product
169   //! Computes <me> = <me>.Cross(Coord1.Cross(Coord2))
170     void CrossCross (const gp_XYZ& Coord1, const gp_XYZ& Coord2);
171   
172   //! Triple vector product
173   //! computes New = <me>.Cross(Coord1.Cross(Coord2))
174     gp_XYZ CrossCrossed (const gp_XYZ& Coord1, const gp_XYZ& Coord2) const;
175   
176   //! divides <me> by a real.
177     void Divide (const Standard_Real Scalar);
178   void operator /= (const Standard_Real Scalar)
179 {
180   Divide(Scalar);
181 }
182   
183   //! divides <me> by a real.
184     gp_XYZ Divided (const Standard_Real Scalar) const;
185   gp_XYZ operator / (const Standard_Real Scalar) const
186 {
187   return Divided(Scalar);
188 }
189   
190   //! computes the scalar product between <me> and Other
191     Standard_Real Dot (const gp_XYZ& Other) const;
192   Standard_Real operator * (const gp_XYZ& Other) const
193 {
194   return Dot(Other);
195 }
196   
197   //! computes the triple scalar product
198     Standard_Real DotCross (const gp_XYZ& Coord1, const gp_XYZ& Coord2) const;
199   
200
201   //! <me>.X() = <me>.X() * Scalar;
202   //! <me>.Y() = <me>.Y() * Scalar;
203   //! <me>.Z() = <me>.Z() * Scalar;
204     void Multiply (const Standard_Real Scalar);
205   void operator *= (const Standard_Real Scalar)
206 {
207   Multiply(Scalar);
208 }
209   
210
211   //! <me>.X() = <me>.X() * Other.X();
212   //! <me>.Y() = <me>.Y() * Other.Y();
213   //! <me>.Z() = <me>.Z() * Other.Z();
214     void Multiply (const gp_XYZ& Other);
215   void operator *= (const gp_XYZ& Other)
216 {
217   Multiply(Other);
218 }
219   
220   //! <me> = Matrix * <me>
221     void Multiply (const gp_Mat& Matrix);
222   void operator *= (const gp_Mat& Matrix)
223 {
224   Multiply(Matrix);
225 }
226   
227
228   //! New.X() = <me>.X() * Scalar;
229   //! New.Y() = <me>.Y() * Scalar;
230   //! New.Z() = <me>.Z() * Scalar;
231     gp_XYZ Multiplied (const Standard_Real Scalar) const;
232   gp_XYZ operator * (const Standard_Real Scalar) const
233 {
234   return Multiplied(Scalar);
235 }
236   
237
238   //! new.X() = <me>.X() * Other.X();
239   //! new.Y() = <me>.Y() * Other.Y();
240   //! new.Z() = <me>.Z() * Other.Z();
241     gp_XYZ Multiplied (const gp_XYZ& Other) const;
242   
243   //! New = Matrix * <me>
244     gp_XYZ Multiplied (const gp_Mat& Matrix) const;
245   gp_XYZ operator * (const gp_Mat& Matrix) const
246 {
247   return Multiplied(Matrix);
248 }
249   
250
251   //! <me>.X() = <me>.X()/ <me>.Modulus()
252   //! <me>.Y() = <me>.Y()/ <me>.Modulus()
253   //! <me>.Z() = <me>.Z()/ <me>.Modulus()
254   //! Raised if <me>.Modulus() <= Resolution from gp
255     void Normalize();
256   
257
258   //! New.X() = <me>.X()/ <me>.Modulus()
259   //! New.Y() = <me>.Y()/ <me>.Modulus()
260   //! New.Z() = <me>.Z()/ <me>.Modulus()
261   //! Raised if <me>.Modulus() <= Resolution from gp
262     gp_XYZ Normalized() const;
263   
264
265   //! <me>.X() = -<me>.X()
266   //! <me>.Y() = -<me>.Y()
267   //! <me>.Z() = -<me>.Z()
268     void Reverse();
269   
270
271   //! New.X() = -<me>.X()
272   //! New.Y() = -<me>.Y()
273   //! New.Z() = -<me>.Z()
274     gp_XYZ Reversed() const;
275   
276
277   //! <me>.X() = <me>.X() - Other.X()
278   //! <me>.Y() = <me>.Y() - Other.Y()
279   //! <me>.Z() = <me>.Z() - Other.Z()
280     void Subtract (const gp_XYZ& Right);
281   void operator -= (const gp_XYZ& Right)
282 {
283   Subtract(Right);
284 }
285   
286
287   //! new.X() = <me>.X() - Other.X()
288   //! new.Y() = <me>.Y() - Other.Y()
289   //! new.Z() = <me>.Z() - Other.Z()
290     gp_XYZ Subtracted (const gp_XYZ& Right) const;
291   gp_XYZ operator - (const gp_XYZ& Right) const
292 {
293   return Subtracted(Right);
294 }
295   
296
297   //! <me> is set to the following linear form :
298   //! A1 * XYZ1 + A2 * XYZ2 + A3 * XYZ3 + XYZ4
299     void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2, const Standard_Real A3, const gp_XYZ& XYZ3, const gp_XYZ& XYZ4);
300   
301
302   //! <me> is set to the following linear form :
303   //! A1 * XYZ1 + A2 * XYZ2 + A3 * XYZ3
304     void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2, const Standard_Real A3, const gp_XYZ& XYZ3);
305   
306
307   //! <me> is set to the following linear form :
308   //! A1 * XYZ1 + A2 * XYZ2 + XYZ3
309     void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2, const gp_XYZ& XYZ3);
310   
311
312   //! <me> is set to the following linear form :
313   //! A1 * XYZ1 + A2 * XYZ2
314     void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const Standard_Real A2, const gp_XYZ& XYZ2);
315   
316
317   //! <me> is set to the following linear form :
318   //! A1 * XYZ1 + XYZ2
319     void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const gp_XYZ& XYZ2);
320   
321
322   //! <me> is set to the following linear form :
323   //! XYZ1 + XYZ2
324     void SetLinearForm (const gp_XYZ& XYZ1, const gp_XYZ& XYZ2);
325
326
327
328
329 protected:
330
331
332
333
334
335 private:
336
337
338
339   Standard_Real x;
340   Standard_Real y;
341   Standard_Real z;
342
343
344 };
345
346
347 #include <gp_XYZ.lxx>
348
349
350
351
352
353 #endif // _gp_XYZ_HeaderFile