Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 | 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 3 | // |
973c2be1 | 4 | // This file is part of Open CASCADE Technology software library. |
b311480e | 5 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 11 | // |
973c2be1 | 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. | |
b311480e | 14 | |
7fd59977 | 15 | // LPA et JCV 07/92 |
16 | ||
17 | #include <gp.hxx> | |
18 | #include <gp_Mat.hxx> | |
19 | #include <Standard_ConstructionError.hxx> | |
20 | #include <Standard_OutOfRange.hxx> | |
21 | ||
22 | inline gp_XYZ::gp_XYZ () : x(0.), y(0.), z(0.) { } | |
23 | ||
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) { } | |
27 | ||
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; } | |
32 | ||
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); | |
36 | (&x)[i-1] = X; | |
37 | } | |
38 | ||
39 | inline void gp_XYZ::SetX (const Standard_Real X) | |
40 | { x = X; } | |
41 | ||
42 | inline void gp_XYZ::SetY (const Standard_Real Y) | |
43 | { y = Y; } | |
44 | ||
45 | inline void gp_XYZ::SetZ (const Standard_Real Z) | |
46 | { z = Z; } | |
47 | ||
48 | inline Standard_Real gp_XYZ::Coord (const Standard_Integer i) const { | |
49 | Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL); | |
50 | return (&x)[i-1]; | |
51 | } | |
52 | ||
db71702d | 53 | inline Standard_Real& gp_XYZ::ChangeCoord(const Standard_Integer theIndex) |
54 | { | |
55 | Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 3,NULL); | |
56 | return (&x)[theIndex - 1]; | |
57 | } | |
58 | ||
7fd59977 | 59 | inline void gp_XYZ::Coord (Standard_Real& X, |
60 | Standard_Real& Y, | |
61 | Standard_Real& Z) const | |
62 | { X = x; Y = y; Z = z; } | |
63 | ||
64 | inline Standard_Real gp_XYZ::X () const | |
65 | { return x; } | |
66 | ||
67 | inline Standard_Real gp_XYZ::Y () const | |
68 | { return y; } | |
69 | ||
70 | inline Standard_Real gp_XYZ::Z () const | |
71 | { return z; } | |
72 | ||
73 | inline Standard_Real gp_XYZ::Modulus () const { | |
74 | return sqrt (x * x + y * y + z * z); | |
75 | } | |
76 | ||
77 | inline Standard_Real gp_XYZ::SquareModulus () const { | |
78 | return (x * x + y * y + z * z); | |
79 | } | |
80 | ||
81 | inline void gp_XYZ::Add (const gp_XYZ& Other) | |
82 | { | |
83 | x += Other.x; | |
84 | y += Other.y; | |
85 | z += Other.z; | |
86 | } | |
87 | ||
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); | |
90 | } | |
91 | ||
92 | inline void gp_XYZ::Cross (const gp_XYZ& Right) | |
93 | { | |
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; | |
97 | x = Xresult; | |
98 | y = Yresult; | |
99 | } | |
100 | ||
101 | inline gp_XYZ gp_XYZ::Crossed (const gp_XYZ& Right) const | |
102 | { | |
103 | return gp_XYZ (y * Right.z - z * Right.y, | |
104 | z * Right.x - x * Right.z, | |
105 | x * Right.y - y * Right.x); | |
106 | } | |
107 | ||
108 | inline Standard_Real gp_XYZ::CrossMagnitude (const gp_XYZ& Right) const | |
109 | { | |
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); | |
114 | } | |
115 | ||
116 | inline Standard_Real gp_XYZ::CrossSquareMagnitude (const gp_XYZ& Right) const | |
117 | { | |
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; | |
122 | } | |
123 | ||
124 | inline void gp_XYZ::CrossCross (const gp_XYZ& Coord1, | |
125 | const gp_XYZ& Coord2) | |
126 | { | |
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); | |
133 | z = | |
134 | x * (Coord1.z * Coord2.x - Coord1.x * Coord2.z) - | |
135 | y * (Coord1.y * Coord2.z - Coord1.z * Coord2.y); | |
136 | x = Xresult; | |
137 | y = Yresult; | |
138 | } | |
139 | ||
140 | inline gp_XYZ gp_XYZ::CrossCrossed (const gp_XYZ& Coord1, | |
141 | const gp_XYZ& Coord2) const | |
142 | { | |
143 | gp_XYZ Coord0 = *this; | |
144 | Coord0.CrossCross (Coord1, Coord2); | |
145 | return Coord0; | |
146 | } | |
147 | ||
148 | inline void gp_XYZ::Divide (const Standard_Real Scalar) | |
149 | { | |
150 | x /= Scalar; | |
151 | y /= Scalar; | |
152 | z /= Scalar; | |
153 | } | |
154 | ||
155 | inline gp_XYZ gp_XYZ::Divided (const Standard_Real Scalar) const { | |
156 | return gp_XYZ(x / Scalar,y / Scalar,z / Scalar); | |
157 | } | |
158 | ||
159 | inline Standard_Real gp_XYZ::Dot (const gp_XYZ& Other) const { | |
160 | return(x * Other.x + y * Other.y + z * Other.z); | |
161 | } | |
162 | ||
163 | inline Standard_Real gp_XYZ::DotCross (const gp_XYZ& Coord1, | |
164 | const gp_XYZ& Coord2) const | |
165 | { | |
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); | |
170 | } | |
171 | ||
172 | inline void gp_XYZ::Multiply (const Standard_Real Scalar) | |
173 | { | |
174 | x *= Scalar; | |
175 | y *= Scalar; | |
176 | z *= Scalar; | |
177 | } | |
178 | ||
179 | inline void gp_XYZ::Multiply (const gp_XYZ& Other) | |
180 | { | |
181 | x *= Other.x; | |
182 | y *= Other.y; | |
183 | z *= Other.z; | |
184 | } | |
185 | ||
186 | inline void gp_XYZ::Multiply (const gp_Mat& Matrix) | |
187 | { | |
0c7386be RK |
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; | |
7fd59977 | 191 | x = Xresult; |
192 | y = Yresult; | |
193 | } | |
194 | ||
195 | inline gp_XYZ gp_XYZ::Multiplied (const Standard_Real Scalar) const { | |
196 | return gp_XYZ(x * Scalar,y * Scalar,z * Scalar); | |
197 | } | |
198 | ||
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); | |
201 | } | |
202 | ||
203 | inline gp_XYZ gp_XYZ::Multiplied (const gp_Mat& Matrix) const | |
204 | { | |
0c7386be RK |
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); | |
7fd59977 | 208 | } |
209 | ||
210 | inline void gp_XYZ::Normalize () | |
211 | { | |
212 | Standard_Real D = Modulus(); | |
213 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); | |
214 | x = x / D; y = y / D; z = z / D; | |
215 | } | |
216 | ||
217 | inline gp_XYZ gp_XYZ::Normalized () const | |
218 | { | |
219 | Standard_Real D = Modulus(); | |
220 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); | |
221 | return gp_XYZ (x / D, y / D, z / D); | |
222 | } | |
223 | ||
224 | inline void gp_XYZ::Reverse () | |
225 | { | |
226 | x = - x; | |
227 | y = - y; | |
228 | z = - z; | |
229 | } | |
230 | ||
231 | inline gp_XYZ gp_XYZ::Reversed () const | |
232 | { | |
233 | return gp_XYZ(-x, -y, -z); | |
234 | } | |
235 | ||
236 | inline void gp_XYZ::Subtract (const gp_XYZ& Right) | |
237 | { | |
238 | x-=Right.x; | |
239 | y-=Right.y; | |
240 | z-=Right.z; | |
241 | } | |
242 | ||
243 | inline gp_XYZ gp_XYZ::Subtracted (const gp_XYZ& Right) const | |
244 | { | |
245 | return gp_XYZ(x - Right.x, y - Right.y, z - Right.z); | |
246 | } | |
247 | ||
248 | inline void gp_XYZ::SetLinearForm (const Standard_Real L, | |
249 | const gp_XYZ& Left, | |
250 | const Standard_Real R, | |
251 | const gp_XYZ& Right) { | |
252 | ||
253 | x = L * Left.x + R * Right.x; | |
254 | y = L * Left.y + R * Right.y; | |
255 | z = L * Left.z + R * Right.z; | |
256 | } | |
257 | ||
258 | inline void gp_XYZ::SetLinearForm(const Standard_Real L, | |
259 | const gp_XYZ& Left, | |
260 | const gp_XYZ& Right) { | |
261 | x = L * Left.x + Right.x; | |
262 | y = L * Left.y + Right.y; | |
263 | z = L * Left.z + Right.z; | |
264 | } | |
265 | ||
266 | inline void gp_XYZ::SetLinearForm (const gp_XYZ& Left, const gp_XYZ& Right) { | |
267 | x = Left.x + Right.x; | |
268 | y = Left.y + Right.y; | |
269 | z = Left.z + Right.z; | |
270 | } | |
271 | ||
272 | inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, | |
273 | const Standard_Real A2, const gp_XYZ& XYZ2, | |
274 | const Standard_Real A3, const gp_XYZ& XYZ3) { | |
275 | ||
276 | x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x; | |
277 | y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y; | |
278 | z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z; | |
279 | } | |
280 | ||
281 | inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, | |
282 | const Standard_Real A2, const gp_XYZ& XYZ2, | |
283 | const gp_XYZ& XYZ3) { | |
284 | x = A1 * XYZ1.x + A2 * XYZ2.x + XYZ3.x; | |
285 | y = A1 * XYZ1.y + A2 * XYZ2.y + XYZ3.y; | |
286 | z = A1 * XYZ1.z + A2 * XYZ2.z + XYZ3.z; | |
287 | } | |
288 | ||
289 | inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, | |
290 | const Standard_Real A2, const gp_XYZ& XYZ2, | |
291 | const Standard_Real A3, const gp_XYZ& XYZ3, | |
292 | const gp_XYZ& XYZ4) { | |
293 | x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x + XYZ4.x; | |
294 | y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y + XYZ4.y; | |
295 | z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z + XYZ4.z; | |
296 | ||
297 | } | |
298 | ||
299 | inline gp_XYZ operator* (const gp_Mat& Matrix, const gp_XYZ& Coord1) { | |
300 | return Coord1.Multiplied (Matrix); | |
301 | } | |
302 | ||
303 | inline gp_XYZ operator* (const Standard_Real Scalar, const gp_XYZ& Coord1) { | |
304 | return Coord1.Multiplied (Scalar); | |
305 | } | |
306 | ||
307 | ||
308 | ||
309 | ||
310 | ||
311 |