1 // Copyright (c) 1995-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.
19 #include <Standard_ConstructionError.hxx>
20 #include <Standard_OutOfRange.hxx>
22 inline gp_XYZ::gp_XYZ () : x(0.), y(0.), z(0.) { }
24 inline gp_XYZ::gp_XYZ (const Standard_Real X,
25 const Standard_Real Y,
26 const Standard_Real Z) : x(X),y(Y),z(Z) { }
28 inline void gp_XYZ::SetCoord (const Standard_Real X,
29 const Standard_Real Y,
30 const Standard_Real Z)
31 { x = X; y = Y; z = Z; }
33 inline void gp_XYZ::SetCoord (const Standard_Integer i,
34 const Standard_Real X) {
35 Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL);
39 inline void gp_XYZ::SetX (const Standard_Real X)
42 inline void gp_XYZ::SetY (const Standard_Real Y)
45 inline void gp_XYZ::SetZ (const Standard_Real Z)
48 inline Standard_Real gp_XYZ::Coord (const Standard_Integer i) const {
49 Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL);
53 inline Standard_Real& gp_XYZ::ChangeCoord(const Standard_Integer theIndex)
55 Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 3,NULL);
56 return (&x)[theIndex - 1];
59 inline void gp_XYZ::Coord (Standard_Real& X,
61 Standard_Real& Z) const
62 { X = x; Y = y; Z = z; }
64 inline Standard_Real gp_XYZ::X () const
67 inline Standard_Real gp_XYZ::Y () const
70 inline Standard_Real gp_XYZ::Z () const
73 inline Standard_Real gp_XYZ::Modulus () const {
74 return sqrt (x * x + y * y + z * z);
77 inline Standard_Real gp_XYZ::SquareModulus () const {
78 return (x * x + y * y + z * z);
81 inline void gp_XYZ::Add (const gp_XYZ& Other)
88 inline gp_XYZ gp_XYZ::Added (const gp_XYZ& Other) const {
89 return gp_XYZ(x + Other.x,y + Other.y,z + Other.z);
92 inline void gp_XYZ::Cross (const gp_XYZ& Right)
94 Standard_Real Xresult = y * Right.z - z * Right.y;
95 Standard_Real Yresult = z * Right.x - x * Right.z;
96 z = x * Right.y - y * Right.x;
101 inline gp_XYZ gp_XYZ::Crossed (const gp_XYZ& Right) const
103 return gp_XYZ (y * Right.z - z * Right.y,
104 z * Right.x - x * Right.z,
105 x * Right.y - y * Right.x);
108 inline Standard_Real gp_XYZ::CrossMagnitude (const gp_XYZ& Right) const
110 Standard_Real Xresult = y * Right.z - z * Right.y;
111 Standard_Real Yresult = z * Right.x - x * Right.z;
112 Standard_Real Zresult = x * Right.y - y * Right.x;
113 return sqrt(Xresult * Xresult + Yresult * Yresult + Zresult * Zresult);
116 inline Standard_Real gp_XYZ::CrossSquareMagnitude (const gp_XYZ& Right) const
118 Standard_Real Xresult = y * Right.z - z * Right.y;
119 Standard_Real Yresult = z * Right.x - x * Right.z;
120 Standard_Real Zresult = x * Right.y - y * Right.x;
121 return Xresult * Xresult + Yresult * Yresult + Zresult * Zresult;
124 inline void gp_XYZ::CrossCross (const gp_XYZ& Coord1,
125 const gp_XYZ& Coord2)
127 Standard_Real Xresult =
128 y * (Coord1.x * Coord2.y - Coord1.y * Coord2.x) -
129 z * (Coord1.z * Coord2.x - Coord1.x * Coord2.z);
130 Standard_Real Yresult =
131 z * (Coord1.y * Coord2.z - Coord1.z * Coord2.y) -
132 x * (Coord1.x * Coord2.y - Coord1.y * Coord2.x);
134 x * (Coord1.z * Coord2.x - Coord1.x * Coord2.z) -
135 y * (Coord1.y * Coord2.z - Coord1.z * Coord2.y);
140 inline gp_XYZ gp_XYZ::CrossCrossed (const gp_XYZ& Coord1,
141 const gp_XYZ& Coord2) const
143 gp_XYZ Coord0 = *this;
144 Coord0.CrossCross (Coord1, Coord2);
148 inline void gp_XYZ::Divide (const Standard_Real Scalar)
155 inline gp_XYZ gp_XYZ::Divided (const Standard_Real Scalar) const {
156 return gp_XYZ(x / Scalar,y / Scalar,z / Scalar);
159 inline Standard_Real gp_XYZ::Dot (const gp_XYZ& Other) const {
160 return(x * Other.x + y * Other.y + z * Other.z);
163 inline Standard_Real gp_XYZ::DotCross (const gp_XYZ& Coord1,
164 const gp_XYZ& Coord2) const
166 Standard_Real Xresult = Coord1.y * Coord2.z - Coord1.z * Coord2.y;
167 Standard_Real Yresult = Coord1.z * Coord2.x - Coord1.x * Coord2.z;
168 Standard_Real Zresult = Coord1.x * Coord2.y - Coord1.y * Coord2.x;
169 return ( x * Xresult + y * Yresult + z * Zresult);
172 inline void gp_XYZ::Multiply (const Standard_Real Scalar)
179 inline void gp_XYZ::Multiply (const gp_XYZ& Other)
186 inline void gp_XYZ::Multiply (const gp_Mat& Matrix)
188 Standard_Real Xresult = Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z;
189 Standard_Real Yresult = Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z;
190 z = Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z;
195 inline gp_XYZ gp_XYZ::Multiplied (const Standard_Real Scalar) const {
196 return gp_XYZ(x * Scalar,y * Scalar,z * Scalar);
199 inline gp_XYZ gp_XYZ::Multiplied (const gp_XYZ& Other) const {
200 return gp_XYZ(x * Other.x, y * Other.y, z * Other.z);
203 inline gp_XYZ gp_XYZ::Multiplied (const gp_Mat& Matrix) const
205 return gp_XYZ (Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z,
206 Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z,
207 Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z);
210 inline void gp_XYZ::Normalize ()
212 Standard_Real D = Modulus();
213 Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
214 "gp_XYZ::Normalize() - vector has zero norm");
215 x = x / D; y = y / D; z = z / D;
218 inline gp_XYZ gp_XYZ::Normalized () const
220 Standard_Real D = Modulus();
221 Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
222 "gp_XYZ::Normalized() - vector has zero norm");
223 return gp_XYZ (x / D, y / D, z / D);
226 inline void gp_XYZ::Reverse ()
233 inline gp_XYZ gp_XYZ::Reversed () const
235 return gp_XYZ(-x, -y, -z);
238 inline void gp_XYZ::Subtract (const gp_XYZ& Right)
245 inline gp_XYZ gp_XYZ::Subtracted (const gp_XYZ& Right) const
247 return gp_XYZ(x - Right.x, y - Right.y, z - Right.z);
250 inline void gp_XYZ::SetLinearForm (const Standard_Real L,
252 const Standard_Real R,
253 const gp_XYZ& Right) {
255 x = L * Left.x + R * Right.x;
256 y = L * Left.y + R * Right.y;
257 z = L * Left.z + R * Right.z;
260 inline void gp_XYZ::SetLinearForm(const Standard_Real L,
262 const gp_XYZ& Right) {
263 x = L * Left.x + Right.x;
264 y = L * Left.y + Right.y;
265 z = L * Left.z + Right.z;
268 inline void gp_XYZ::SetLinearForm (const gp_XYZ& Left, const gp_XYZ& Right) {
269 x = Left.x + Right.x;
270 y = Left.y + Right.y;
271 z = Left.z + Right.z;
274 inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1,
275 const Standard_Real A2, const gp_XYZ& XYZ2,
276 const Standard_Real A3, const gp_XYZ& XYZ3) {
278 x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x;
279 y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y;
280 z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z;
283 inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1,
284 const Standard_Real A2, const gp_XYZ& XYZ2,
285 const gp_XYZ& XYZ3) {
286 x = A1 * XYZ1.x + A2 * XYZ2.x + XYZ3.x;
287 y = A1 * XYZ1.y + A2 * XYZ2.y + XYZ3.y;
288 z = A1 * XYZ1.z + A2 * XYZ2.z + XYZ3.z;
291 inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1,
292 const Standard_Real A2, const gp_XYZ& XYZ2,
293 const Standard_Real A3, const gp_XYZ& XYZ3,
294 const gp_XYZ& XYZ4) {
295 x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x + XYZ4.x;
296 y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y + XYZ4.y;
297 z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z + XYZ4.z;
301 inline gp_XYZ operator* (const gp_Mat& Matrix, const gp_XYZ& Coord1) {
302 return Coord1.Multiplied (Matrix);
305 inline gp_XYZ operator* (const Standard_Real Scalar, const gp_XYZ& Coord1) {
306 return Coord1.Multiplied (Scalar);