1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _gp_XYZ_HeaderFile
16 #define _gp_XYZ_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
22 #include <Standard_Real.hxx>
23 #include <Standard_Integer.hxx>
24 #include <Standard_Boolean.hxx>
25 class Standard_ConstructionError;
26 class Standard_OutOfRange;
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.
44 //! Creates an XYZ object with zero co-ordinates (0,0,0)
47 //! creates an XYZ with given coordinates
48 gp_XYZ(const Standard_Real X, const Standard_Real Y, const Standard_Real Z);
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);
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);
62 //! Assigns the given value to the X coordinate
63 void SetX (const Standard_Real X);
65 //! Assigns the given value to the Y coordinate
66 void SetY (const Standard_Real Y);
68 //! Assigns the given value to the Z coordinate
69 void SetZ (const Standard_Real Z);
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
77 //! Raises OutOfRange if Index != {1, 2, 3}.
78 Standard_Real Coord (const Standard_Integer Index) const;
80 Standard_Real& ChangeCoord (const Standard_Integer theIndex);
82 void Coord (Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const;
84 //! Returns a const ptr to coordinates location.
85 //! Is useful for algorithms, but DOES NOT PERFORM
87 inline const Standard_Real* GetData() const { return (&x); }
89 //! Returns a ptr to coordinates location.
90 //! Is useful for algorithms, but DOES NOT PERFORM
92 inline Standard_Real* ChangeData() { return (&x); }
94 //! Returns the X coordinate
95 Standard_Real X() const;
97 //! Returns the Y coordinate
98 Standard_Real Y() const;
100 //! Returns the Z coordinate
101 Standard_Real Z() const;
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;
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;
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;
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)
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
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)
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
155 return Crossed(Right);
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;
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;
168 //! Triple vector product
169 //! Computes <me> = <me>.Cross(Coord1.Cross(Coord2))
170 void CrossCross (const gp_XYZ& Coord1, const gp_XYZ& Coord2);
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;
176 //! divides <me> by a real.
177 void Divide (const Standard_Real Scalar);
178 void operator /= (const Standard_Real Scalar)
183 //! divides <me> by a real.
184 gp_XYZ Divided (const Standard_Real Scalar) const;
185 gp_XYZ operator / (const Standard_Real Scalar) const
187 return Divided(Scalar);
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
197 //! computes the triple scalar product
198 Standard_Real DotCross (const gp_XYZ& Coord1, const gp_XYZ& Coord2) const;
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)
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)
220 //! <me> = Matrix * <me>
221 void Multiply (const gp_Mat& Matrix);
222 void operator *= (const gp_Mat& Matrix)
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
234 return Multiplied(Scalar);
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;
243 //! New = Matrix * <me>
244 gp_XYZ Multiplied (const gp_Mat& Matrix) const;
245 gp_XYZ operator * (const gp_Mat& Matrix) const
247 return Multiplied(Matrix);
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
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;
265 //! <me>.X() = -<me>.X()
266 //! <me>.Y() = -<me>.Y()
267 //! <me>.Z() = -<me>.Z()
271 //! New.X() = -<me>.X()
272 //! New.Y() = -<me>.Y()
273 //! New.Z() = -<me>.Z()
274 gp_XYZ Reversed() const;
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)
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
293 return Subtracted(Right);
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);
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);
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);
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);
317 //! <me> is set to the following linear form :
319 void SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, const gp_XYZ& XYZ2);
322 //! <me> is set to the following linear form :
324 void SetLinearForm (const gp_XYZ& XYZ1, const gp_XYZ& XYZ2);
347 #include <gp_XYZ.lxx>
353 #endif // _gp_XYZ_HeaderFile