Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File gp_XYZ.lxx, JCV 05/12/90 |
2 | // LPA et JCV 07/92 | |
3 | ||
4 | #include <gp.hxx> | |
5 | #include <gp_Mat.hxx> | |
6 | #include <Standard_ConstructionError.hxx> | |
7 | #include <Standard_OutOfRange.hxx> | |
8 | ||
9 | inline gp_XYZ::gp_XYZ () : x(0.), y(0.), z(0.) { } | |
10 | ||
11 | inline gp_XYZ::gp_XYZ (const Standard_Real X, | |
12 | const Standard_Real Y, | |
13 | const Standard_Real Z) : x(X),y(Y),z(Z) { } | |
14 | ||
15 | inline void gp_XYZ::SetCoord (const Standard_Real X, | |
16 | const Standard_Real Y, | |
17 | const Standard_Real Z) | |
18 | { x = X; y = Y; z = Z; } | |
19 | ||
20 | inline void gp_XYZ::SetCoord (const Standard_Integer i, | |
21 | const Standard_Real X) { | |
22 | Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL); | |
23 | (&x)[i-1] = X; | |
24 | } | |
25 | ||
26 | inline void gp_XYZ::SetX (const Standard_Real X) | |
27 | { x = X; } | |
28 | ||
29 | inline void gp_XYZ::SetY (const Standard_Real Y) | |
30 | { y = Y; } | |
31 | ||
32 | inline void gp_XYZ::SetZ (const Standard_Real Z) | |
33 | { z = Z; } | |
34 | ||
35 | inline Standard_Real gp_XYZ::Coord (const Standard_Integer i) const { | |
36 | Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL); | |
37 | return (&x)[i-1]; | |
38 | } | |
39 | ||
40 | inline void gp_XYZ::Coord (Standard_Real& X, | |
41 | Standard_Real& Y, | |
42 | Standard_Real& Z) const | |
43 | { X = x; Y = y; Z = z; } | |
44 | ||
45 | inline Standard_Real gp_XYZ::X () const | |
46 | { return x; } | |
47 | ||
48 | inline Standard_Real gp_XYZ::Y () const | |
49 | { return y; } | |
50 | ||
51 | inline Standard_Real gp_XYZ::Z () const | |
52 | { return z; } | |
53 | ||
54 | inline Standard_Real gp_XYZ::Modulus () const { | |
55 | return sqrt (x * x + y * y + z * z); | |
56 | } | |
57 | ||
58 | inline Standard_Real gp_XYZ::SquareModulus () const { | |
59 | return (x * x + y * y + z * z); | |
60 | } | |
61 | ||
62 | inline void gp_XYZ::Add (const gp_XYZ& Other) | |
63 | { | |
64 | x += Other.x; | |
65 | y += Other.y; | |
66 | z += Other.z; | |
67 | } | |
68 | ||
69 | inline gp_XYZ gp_XYZ::Added (const gp_XYZ& Other) const { | |
70 | return gp_XYZ(x + Other.x,y + Other.y,z + Other.z); | |
71 | } | |
72 | ||
73 | inline void gp_XYZ::Cross (const gp_XYZ& Right) | |
74 | { | |
75 | Standard_Real Xresult = y * Right.z - z * Right.y; | |
76 | Standard_Real Yresult = z * Right.x - x * Right.z; | |
77 | z = x * Right.y - y * Right.x; | |
78 | x = Xresult; | |
79 | y = Yresult; | |
80 | } | |
81 | ||
82 | inline gp_XYZ gp_XYZ::Crossed (const gp_XYZ& Right) const | |
83 | { | |
84 | return gp_XYZ (y * Right.z - z * Right.y, | |
85 | z * Right.x - x * Right.z, | |
86 | x * Right.y - y * Right.x); | |
87 | } | |
88 | ||
89 | inline Standard_Real gp_XYZ::CrossMagnitude (const gp_XYZ& Right) const | |
90 | { | |
91 | Standard_Real Xresult = y * Right.z - z * Right.y; | |
92 | Standard_Real Yresult = z * Right.x - x * Right.z; | |
93 | Standard_Real Zresult = x * Right.y - y * Right.x; | |
94 | return sqrt(Xresult * Xresult + Yresult * Yresult + Zresult * Zresult); | |
95 | } | |
96 | ||
97 | inline Standard_Real gp_XYZ::CrossSquareMagnitude (const gp_XYZ& Right) const | |
98 | { | |
99 | Standard_Real Xresult = y * Right.z - z * Right.y; | |
100 | Standard_Real Yresult = z * Right.x - x * Right.z; | |
101 | Standard_Real Zresult = x * Right.y - y * Right.x; | |
102 | return Xresult * Xresult + Yresult * Yresult + Zresult * Zresult; | |
103 | } | |
104 | ||
105 | inline void gp_XYZ::CrossCross (const gp_XYZ& Coord1, | |
106 | const gp_XYZ& Coord2) | |
107 | { | |
108 | Standard_Real Xresult = | |
109 | y * (Coord1.x * Coord2.y - Coord1.y * Coord2.x) - | |
110 | z * (Coord1.z * Coord2.x - Coord1.x * Coord2.z); | |
111 | Standard_Real Yresult = | |
112 | z * (Coord1.y * Coord2.z - Coord1.z * Coord2.y) - | |
113 | x * (Coord1.x * Coord2.y - Coord1.y * Coord2.x); | |
114 | z = | |
115 | x * (Coord1.z * Coord2.x - Coord1.x * Coord2.z) - | |
116 | y * (Coord1.y * Coord2.z - Coord1.z * Coord2.y); | |
117 | x = Xresult; | |
118 | y = Yresult; | |
119 | } | |
120 | ||
121 | inline gp_XYZ gp_XYZ::CrossCrossed (const gp_XYZ& Coord1, | |
122 | const gp_XYZ& Coord2) const | |
123 | { | |
124 | gp_XYZ Coord0 = *this; | |
125 | Coord0.CrossCross (Coord1, Coord2); | |
126 | return Coord0; | |
127 | } | |
128 | ||
129 | inline void gp_XYZ::Divide (const Standard_Real Scalar) | |
130 | { | |
131 | x /= Scalar; | |
132 | y /= Scalar; | |
133 | z /= Scalar; | |
134 | } | |
135 | ||
136 | inline gp_XYZ gp_XYZ::Divided (const Standard_Real Scalar) const { | |
137 | return gp_XYZ(x / Scalar,y / Scalar,z / Scalar); | |
138 | } | |
139 | ||
140 | inline Standard_Real gp_XYZ::Dot (const gp_XYZ& Other) const { | |
141 | return(x * Other.x + y * Other.y + z * Other.z); | |
142 | } | |
143 | ||
144 | inline Standard_Real gp_XYZ::DotCross (const gp_XYZ& Coord1, | |
145 | const gp_XYZ& Coord2) const | |
146 | { | |
147 | Standard_Real Xresult = Coord1.y * Coord2.z - Coord1.z * Coord2.y; | |
148 | Standard_Real Yresult = Coord1.z * Coord2.x - Coord1.x * Coord2.z; | |
149 | Standard_Real Zresult = Coord1.x * Coord2.y - Coord1.y * Coord2.x; | |
150 | return ( x * Xresult + y * Yresult + z * Zresult); | |
151 | } | |
152 | ||
153 | inline void gp_XYZ::Multiply (const Standard_Real Scalar) | |
154 | { | |
155 | x *= Scalar; | |
156 | y *= Scalar; | |
157 | z *= Scalar; | |
158 | } | |
159 | ||
160 | inline void gp_XYZ::Multiply (const gp_XYZ& Other) | |
161 | { | |
162 | x *= Other.x; | |
163 | y *= Other.y; | |
164 | z *= Other.z; | |
165 | } | |
166 | ||
167 | inline void gp_XYZ::Multiply (const gp_Mat& Matrix) | |
168 | { | |
0c7386be RK |
169 | Standard_Real Xresult = Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z; |
170 | Standard_Real Yresult = Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z; | |
171 | z = Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z; | |
7fd59977 | 172 | x = Xresult; |
173 | y = Yresult; | |
174 | } | |
175 | ||
176 | inline gp_XYZ gp_XYZ::Multiplied (const Standard_Real Scalar) const { | |
177 | return gp_XYZ(x * Scalar,y * Scalar,z * Scalar); | |
178 | } | |
179 | ||
180 | inline gp_XYZ gp_XYZ::Multiplied (const gp_XYZ& Other) const { | |
181 | return gp_XYZ(x * Other.x, y * Other.y, z * Other.z); | |
182 | } | |
183 | ||
184 | inline gp_XYZ gp_XYZ::Multiplied (const gp_Mat& Matrix) const | |
185 | { | |
0c7386be RK |
186 | return gp_XYZ (Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z, |
187 | Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z, | |
188 | Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z); | |
7fd59977 | 189 | } |
190 | ||
191 | inline void gp_XYZ::Normalize () | |
192 | { | |
193 | Standard_Real D = Modulus(); | |
194 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); | |
195 | x = x / D; y = y / D; z = z / D; | |
196 | } | |
197 | ||
198 | inline gp_XYZ gp_XYZ::Normalized () const | |
199 | { | |
200 | Standard_Real D = Modulus(); | |
201 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); | |
202 | return gp_XYZ (x / D, y / D, z / D); | |
203 | } | |
204 | ||
205 | inline void gp_XYZ::Reverse () | |
206 | { | |
207 | x = - x; | |
208 | y = - y; | |
209 | z = - z; | |
210 | } | |
211 | ||
212 | inline gp_XYZ gp_XYZ::Reversed () const | |
213 | { | |
214 | return gp_XYZ(-x, -y, -z); | |
215 | } | |
216 | ||
217 | inline void gp_XYZ::Subtract (const gp_XYZ& Right) | |
218 | { | |
219 | x-=Right.x; | |
220 | y-=Right.y; | |
221 | z-=Right.z; | |
222 | } | |
223 | ||
224 | inline gp_XYZ gp_XYZ::Subtracted (const gp_XYZ& Right) const | |
225 | { | |
226 | return gp_XYZ(x - Right.x, y - Right.y, z - Right.z); | |
227 | } | |
228 | ||
229 | inline void gp_XYZ::SetLinearForm (const Standard_Real L, | |
230 | const gp_XYZ& Left, | |
231 | const Standard_Real R, | |
232 | const gp_XYZ& Right) { | |
233 | ||
234 | x = L * Left.x + R * Right.x; | |
235 | y = L * Left.y + R * Right.y; | |
236 | z = L * Left.z + R * Right.z; | |
237 | } | |
238 | ||
239 | inline void gp_XYZ::SetLinearForm(const Standard_Real L, | |
240 | const gp_XYZ& Left, | |
241 | const gp_XYZ& Right) { | |
242 | x = L * Left.x + Right.x; | |
243 | y = L * Left.y + Right.y; | |
244 | z = L * Left.z + Right.z; | |
245 | } | |
246 | ||
247 | inline void gp_XYZ::SetLinearForm (const gp_XYZ& Left, const gp_XYZ& Right) { | |
248 | x = Left.x + Right.x; | |
249 | y = Left.y + Right.y; | |
250 | z = Left.z + Right.z; | |
251 | } | |
252 | ||
253 | inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, | |
254 | const Standard_Real A2, const gp_XYZ& XYZ2, | |
255 | const Standard_Real A3, const gp_XYZ& XYZ3) { | |
256 | ||
257 | x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x; | |
258 | y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y; | |
259 | z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z; | |
260 | } | |
261 | ||
262 | inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, | |
263 | const Standard_Real A2, const gp_XYZ& XYZ2, | |
264 | const gp_XYZ& XYZ3) { | |
265 | x = A1 * XYZ1.x + A2 * XYZ2.x + XYZ3.x; | |
266 | y = A1 * XYZ1.y + A2 * XYZ2.y + XYZ3.y; | |
267 | z = A1 * XYZ1.z + A2 * XYZ2.z + XYZ3.z; | |
268 | } | |
269 | ||
270 | inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1, | |
271 | const Standard_Real A2, const gp_XYZ& XYZ2, | |
272 | const Standard_Real A3, const gp_XYZ& XYZ3, | |
273 | const gp_XYZ& XYZ4) { | |
274 | x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x + XYZ4.x; | |
275 | y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y + XYZ4.y; | |
276 | z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z + XYZ4.z; | |
277 | ||
278 | } | |
279 | ||
280 | inline gp_XYZ operator* (const gp_Mat& Matrix, const gp_XYZ& Coord1) { | |
281 | return Coord1.Multiplied (Matrix); | |
282 | } | |
283 | ||
284 | inline gp_XYZ operator* (const Standard_Real Scalar, const gp_XYZ& Coord1) { | |
285 | return Coord1.Multiplied (Scalar); | |
286 | } | |
287 | ||
288 | ||
289 | ||
290 | ||
291 | ||
292 |