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 | // JCV 08/01/91 Modif introduction des classes Mat2d et XY dans gp |
16 | ||
17 | #define No_Standard_OutOfRange | |
18 | ||
19 | #include <gp_Trsf2d.ixx> | |
20 | #include <gp.hxx> | |
21 | #include <Standard_ConstructionError.hxx> | |
22 | ||
23 | void gp_Trsf2d::SetMirror (const gp_Ax2d& A) | |
24 | { | |
25 | shape = gp_Ax1Mirror; | |
7fd59977 | 26 | const gp_Dir2d& V = A.Direction (); |
27 | const gp_Pnt2d& P = A.Location (); | |
28 | Standard_Real VX = V.X(); | |
29 | Standard_Real VY = V.Y(); | |
30 | Standard_Real X0 = P.X(); | |
31 | Standard_Real Y0 = P.Y(); | |
7fd59977 | 32 | |
7a8c6a36 | 33 | SetValues(1.0-2.0*VX*VX, -2.0*VX*VY, -2.0*((VX * VX - 1.0)*X0 + (VX*VY*Y0)), |
34 | -2.0*VX*VY, 1.0-2.0*VY*VY, -2.0*((VX*VY*X0)+(VY*VY-1.0)*Y0)); | |
35 | ||
36 | scale = - 1.0; | |
7fd59977 | 37 | } |
38 | ||
39 | void gp_Trsf2d::SetTransformation (const gp_Ax2d& FromA1, | |
40 | const gp_Ax2d& ToA2) | |
41 | { | |
42 | shape = gp_CompoundTrsf; | |
7fd59977 | 43 | //matrix from XOY to A2 : |
44 | const gp_XY& V1 = ToA2.Direction().XY(); | |
45 | gp_XY V2 (-V1.Y(), V1.X()); | |
7a8c6a36 | 46 | |
47 | SetValues(V1.X(), V2.X(), ToA2.Location().X(), | |
48 | V1.Y(), V2.Y(), ToA2.Location().Y()); | |
49 | ||
50 | scale = 1.0; | |
51 | ||
7fd59977 | 52 | matrix.Transpose(); |
53 | loc.Multiply (matrix); | |
54 | loc.Reverse(); | |
55 | //matrix FromA1 to XOY | |
56 | const gp_XY& V3 = FromA1.Direction().XY(); | |
57 | gp_XY V4 (-V3.Y(), V3.X()); | |
58 | gp_Mat2d MA1 (V3, V4); | |
59 | gp_XY MA1loc = FromA1.Location().XY(); | |
60 | //matrix * MA1 => FromA1 ToA2 | |
61 | MA1loc.Multiply (matrix); | |
62 | loc.Add (MA1loc); | |
63 | matrix.Multiply (MA1); | |
64 | } | |
65 | ||
66 | void gp_Trsf2d::SetTransformation (const gp_Ax2d& A) | |
67 | { | |
68 | shape = gp_CompoundTrsf; | |
7fd59977 | 69 | const gp_XY& V1 = A.Direction().XY(); |
70 | gp_XY V2 (-V1.Y(), V1.X()); | |
7a8c6a36 | 71 | |
72 | SetValues(V1.X(), V2.X(), A.Location().X(), | |
73 | V1.Y(), V2.Y(), A.Location().Y()); | |
74 | ||
75 | scale = 1.0; | |
76 | ||
7fd59977 | 77 | matrix.Transpose(); |
78 | loc.Multiply (matrix); | |
79 | loc.Reverse(); | |
80 | } | |
81 | ||
82 | void gp_Trsf2d::SetTranslationPart (const gp_Vec2d& V) | |
83 | { | |
84 | loc = V.XY(); | |
85 | Standard_Real X = loc.X(); | |
86 | if (X < 0) X = - X; | |
87 | Standard_Real Y = loc.Y(); | |
88 | if (Y < 0) Y = - Y; | |
89 | if (X <= gp::Resolution() && Y <= gp::Resolution()) { | |
90 | if (shape == gp_Identity || shape == gp_PntMirror || | |
91 | shape == gp_Scale || shape == gp_Rotation || | |
92 | shape == gp_Ax1Mirror ) { } | |
93 | else if (shape == gp_Translation) { shape = gp_Identity; } | |
94 | else { shape = gp_CompoundTrsf; } | |
95 | } | |
96 | else { | |
97 | if (shape == gp_Translation || shape == gp_Scale || | |
98 | shape == gp_PntMirror) { } | |
99 | else if (shape == gp_Identity) { shape = gp_Translation; } | |
100 | else { shape = gp_CompoundTrsf; } | |
101 | } | |
102 | } | |
103 | ||
104 | void gp_Trsf2d::SetScaleFactor (const Standard_Real S) | |
105 | { | |
106 | if (S == 1.0) { | |
107 | Standard_Real X = loc.X(); | |
108 | if (X < 0) X = - X; | |
109 | Standard_Real Y = loc.Y(); | |
110 | if (Y < 0) Y = - Y; | |
111 | if (X <= gp::Resolution() && Y <= gp::Resolution()) { | |
112 | if (shape == gp_Identity || shape == gp_Rotation) { } | |
113 | else if (shape == gp_Scale) { shape = gp_Identity; } | |
114 | else if (shape == gp_PntMirror) { shape = gp_Translation; } | |
115 | else { shape = gp_CompoundTrsf; } | |
116 | } | |
117 | else { | |
118 | if (shape == gp_Identity || shape == gp_Rotation || | |
119 | shape == gp_Scale) { } | |
120 | else if (shape == gp_PntMirror) { shape = gp_Translation; } | |
121 | else { shape = gp_CompoundTrsf; } | |
122 | } | |
123 | } | |
124 | else if (S == -1) { | |
125 | if (shape == gp_PntMirror || shape == gp_Ax1Mirror) { } | |
126 | else if (shape == gp_Identity || shape == gp_Scale) { | |
127 | shape = gp_PntMirror; | |
128 | } | |
129 | else { shape = gp_CompoundTrsf; } | |
130 | } | |
131 | else { | |
132 | if (shape == gp_Scale) { } | |
133 | else if (shape == gp_Identity || shape == gp_Translation || | |
134 | shape == gp_PntMirror) { shape = gp_Scale; } | |
135 | else { shape = gp_CompoundTrsf; } | |
136 | } | |
137 | scale = S; | |
138 | } | |
139 | ||
140 | gp_Mat2d gp_Trsf2d::VectorialPart () const | |
141 | { | |
142 | if (scale == 1.0) return matrix; | |
143 | gp_Mat2d M = matrix; | |
144 | if (shape == gp_Scale || shape == gp_PntMirror) | |
145 | M.SetDiagonal (matrix.Value(1,1) * scale, matrix.Value(2,2) * scale); | |
146 | else | |
147 | M.Multiply (scale); | |
148 | return M; | |
149 | } | |
150 | ||
151 | Standard_Real gp_Trsf2d::RotationPart () const | |
152 | { | |
153 | return ATan2 ( matrix.Value(2,1), matrix.Value(1,1) ); | |
154 | } | |
155 | ||
156 | void gp_Trsf2d::Invert() | |
157 | { | |
158 | // -1 | |
159 | // X' = scale * R * X + T => X = (R / scale) * ( X' - T) | |
160 | // | |
161 | // Pour les gp_Trsf2d puisque le scale est extrait de la matrice R | |
162 | // on a toujours determinant (R) = 1 et R-1 = R transposee. | |
163 | if (shape == gp_Identity) { } | |
164 | else if ( shape == gp_Translation || shape == gp_PntMirror) { | |
165 | loc.Reverse(); | |
166 | } | |
167 | else if ( shape == gp_Scale) { | |
168 | Standard_Real As = scale; | |
169 | if (As < 0) As = - As; | |
170 | Standard_ConstructionError_Raise_if(As <= gp::Resolution(),""); | |
171 | scale = 1.0 / scale; | |
172 | loc.Multiply (-scale); | |
173 | } | |
174 | else { | |
175 | Standard_Real As = scale; | |
176 | if (As < 0) As = - As; | |
177 | Standard_ConstructionError_Raise_if(As <= gp::Resolution(),""); | |
178 | scale = 1.0 / scale; | |
179 | matrix.Transpose(); | |
180 | loc.Multiply (matrix); | |
181 | loc.Multiply (-scale); | |
182 | } | |
183 | } | |
184 | ||
185 | void gp_Trsf2d::Multiply(const gp_Trsf2d& T) | |
186 | { | |
187 | if (T.shape == gp_Identity) { } | |
188 | else if (shape == gp_Identity) { | |
189 | shape = T.shape; | |
190 | scale = T.scale; | |
191 | loc = T.loc; | |
192 | matrix = T.matrix; | |
193 | } | |
194 | else if (shape == gp_Rotation && T.shape == gp_Rotation) { | |
195 | if (loc.X() != 0.0 || loc.Y() != 0.0) { | |
196 | loc.Add (T.loc.Multiplied (matrix)); | |
197 | } | |
198 | matrix.Multiply(T.matrix); | |
199 | } | |
200 | else if (shape == gp_Translation && T.shape == gp_Translation) { | |
201 | loc.Add (T.loc); | |
202 | } | |
203 | else if (shape == gp_Scale && T.shape == gp_Scale) { | |
204 | loc.Add (T.loc.Multiplied(scale)); | |
205 | scale = scale * T.scale; | |
206 | } | |
207 | else if (shape == gp_PntMirror && T.shape == gp_PntMirror) { | |
208 | scale = 1.0; | |
209 | shape = gp_Translation; | |
210 | loc.Add (T.loc.Reversed()); | |
211 | } | |
212 | else if (shape == gp_Ax1Mirror && T.shape == gp_Ax1Mirror) { | |
213 | shape = gp_Rotation; | |
4714a7a6 SJ |
214 | gp_XY Tloc (T.loc); |
215 | Tloc.Multiply (matrix); | |
216 | Tloc.Multiply (scale); | |
217 | scale = scale * T.scale; | |
218 | loc.Add (Tloc); | |
219 | matrix.Multiply (T.matrix); | |
7fd59977 | 220 | } |
221 | else if ((shape == gp_CompoundTrsf || shape == gp_Rotation || | |
222 | shape == gp_Ax1Mirror) && T.shape == gp_Translation) { | |
223 | gp_XY Tloc (T.loc); | |
224 | Tloc.Multiply (matrix); | |
225 | if (scale != 1.0) Tloc.Multiply (scale); | |
226 | loc.Add (Tloc); | |
227 | } | |
228 | else if ((shape == gp_Scale || shape == gp_PntMirror) | |
229 | && T.shape == gp_Translation) { | |
230 | gp_XY Tloc (T.loc); | |
231 | Tloc.Multiply (scale); | |
232 | loc.Add (Tloc); | |
233 | } | |
234 | else if (shape == gp_Translation && | |
235 | (T.shape == gp_CompoundTrsf || | |
236 | T.shape == gp_Rotation || T.shape == gp_Ax1Mirror)) { | |
237 | shape = gp_CompoundTrsf; | |
238 | scale = T.scale; | |
239 | loc.Add (T.loc); | |
240 | matrix = T.matrix; | |
241 | } | |
242 | else if (shape == gp_Translation && | |
243 | (T.shape == gp_Scale || T.shape == gp_PntMirror)) { | |
244 | shape = T.shape; | |
245 | loc.Add (T.loc); | |
246 | scale = T.scale; | |
247 | } | |
248 | else if ((shape == gp_PntMirror || shape == gp_Scale) && | |
249 | (T.shape == gp_PntMirror || T.shape == gp_Scale)) { | |
250 | shape = gp_CompoundTrsf; | |
251 | gp_XY Tloc (T.loc); | |
252 | Tloc.Multiply (scale); | |
253 | loc.Add (Tloc); | |
254 | scale = scale * T.scale; | |
255 | } | |
256 | else if ((shape == gp_CompoundTrsf || shape == gp_Rotation || | |
257 | shape == gp_Ax1Mirror) | |
258 | && (T.shape == gp_Scale || T.shape == gp_PntMirror)) { | |
259 | shape = gp_CompoundTrsf; | |
260 | gp_XY Tloc (T.loc); | |
261 | Tloc.Multiply(matrix); | |
262 | if (scale == 1.0) scale = T.scale; | |
263 | else { | |
264 | Tloc.Multiply (scale); | |
265 | scale = scale * T.scale; | |
266 | } | |
267 | loc.Add (Tloc); | |
268 | } | |
269 | else if ((T.shape == gp_CompoundTrsf || T.shape == gp_Rotation || | |
270 | T.shape == gp_Ax1Mirror) | |
271 | && (shape == gp_Scale || shape == gp_PntMirror)) { | |
272 | shape = gp_CompoundTrsf; | |
273 | gp_XY Tloc (T.loc); | |
274 | Tloc.Multiply (scale); | |
275 | scale = scale * T.scale; | |
276 | loc.Add (Tloc); | |
277 | matrix = T.matrix; | |
278 | } | |
279 | else { | |
280 | shape = gp_CompoundTrsf; | |
281 | gp_XY Tloc (T.loc); | |
282 | Tloc.Multiply (matrix); | |
283 | if (scale != 1.0) { | |
284 | Tloc.Multiply (scale); | |
285 | scale = scale * T.scale; | |
286 | } | |
287 | else { scale = T.scale; } | |
288 | loc.Add (Tloc); | |
289 | matrix.Multiply (T.matrix); | |
290 | } | |
291 | } | |
292 | ||
293 | void gp_Trsf2d::Power (const Standard_Integer N) | |
294 | { | |
295 | if (shape == gp_Identity) { } | |
296 | else { | |
297 | if (N == 0) { | |
298 | scale = 1.0; | |
299 | shape = gp_Identity; | |
300 | matrix.SetIdentity(); | |
301 | loc = gp_XY (0.0, 0.0); | |
302 | } | |
303 | else if (N == 1) { } | |
304 | else if (N == -1) Invert(); | |
305 | else { | |
306 | if (N < 0) Invert(); | |
307 | if (shape == gp_Translation) { | |
308 | Standard_Integer Npower = N; | |
309 | if (Npower < 0) Npower = - Npower; | |
310 | Npower--; | |
311 | gp_XY Temploc = loc; | |
302f96fb | 312 | for(;;) { |
7fd59977 | 313 | if (IsOdd(Npower)) loc.Add (Temploc); |
314 | if (Npower == 1) break; | |
315 | Temploc.Add (Temploc); | |
316 | Npower = Npower/2; | |
317 | } | |
318 | } | |
319 | else if (shape == gp_Scale) { | |
320 | Standard_Integer Npower = N; | |
321 | if (Npower < 0) Npower = - Npower; | |
322 | Npower--; | |
323 | gp_XY Temploc = loc; | |
324 | Standard_Real Tempscale = scale; | |
302f96fb | 325 | for(;;) { |
7fd59977 | 326 | if (IsOdd(Npower)) { |
327 | loc.Add (Temploc.Multiplied(scale)); | |
328 | scale = scale * Tempscale; | |
329 | } | |
330 | if (Npower == 1) break; | |
331 | Temploc.Add (Temploc.Multiplied(Tempscale)); | |
332 | Tempscale = Tempscale * Tempscale; | |
333 | Npower = Npower/2; | |
334 | } | |
335 | } | |
336 | else if (shape == gp_Rotation) { | |
337 | Standard_Integer Npower = N; | |
338 | if (Npower < 0) Npower = - Npower; | |
339 | Npower--; | |
340 | gp_Mat2d Tempmatrix (matrix); | |
341 | if (loc.X() == 0.0 && loc.Y() == 0.0) { | |
302f96fb | 342 | for(;;) { |
7fd59977 | 343 | if (IsOdd(Npower)) matrix.Multiply (Tempmatrix); |
344 | if (Npower == 1) break; | |
345 | Tempmatrix.Multiply (Tempmatrix); | |
346 | Npower = Npower/2; | |
347 | } | |
348 | } | |
349 | else { | |
350 | gp_XY Temploc = loc; | |
302f96fb | 351 | for(;;) { |
7fd59977 | 352 | if (IsOdd(Npower)) { |
353 | loc.Add (Temploc.Multiplied (matrix)); | |
354 | matrix.Multiply (Tempmatrix); | |
355 | } | |
356 | if (Npower == 1) break; | |
357 | Temploc.Add (Temploc.Multiplied (Tempmatrix)); | |
358 | Tempmatrix.Multiply (Tempmatrix); | |
359 | Npower = Npower/2; | |
360 | } | |
361 | } | |
362 | } | |
363 | else if (shape == gp_PntMirror || shape == gp_Ax1Mirror) { | |
364 | if (IsEven (N)) { | |
365 | shape = gp_Identity; | |
366 | scale = 1.0; | |
367 | matrix.SetIdentity (); | |
368 | loc.SetCoord (0.0, 0.0); | |
369 | } | |
370 | } | |
371 | else { | |
372 | shape = gp_CompoundTrsf; | |
373 | Standard_Integer Npower = N; | |
374 | if (Npower < 0) Npower = - Npower; | |
375 | Npower--; | |
376 | matrix.SetDiagonal (scale*matrix.Value(1,1), | |
377 | scale*matrix.Value(2,2)); | |
378 | gp_XY Temploc = loc; | |
379 | Standard_Real Tempscale = scale; | |
380 | gp_Mat2d Tempmatrix (matrix); | |
302f96fb | 381 | for(;;) { |
7fd59977 | 382 | if (IsOdd(Npower)) { |
383 | loc.Add ((Temploc.Multiplied (matrix)).Multiplied (scale)); | |
384 | scale = scale * Tempscale; | |
385 | matrix.Multiply (Tempmatrix); | |
386 | } | |
387 | if (Npower == 1) break; | |
388 | Tempscale = Tempscale * Tempscale; | |
389 | Temploc.Add ( (Temploc.Multiplied (Tempmatrix)).Multiplied | |
390 | (Tempscale) | |
391 | ); | |
392 | Tempmatrix.Multiply (Tempmatrix); | |
393 | Npower = Npower/2; | |
394 | } | |
395 | } | |
396 | } | |
397 | } | |
398 | } | |
399 | ||
400 | void gp_Trsf2d::PreMultiply (const gp_Trsf2d& T) | |
401 | { | |
402 | if (T.shape == gp_Identity) { } | |
403 | else if (shape == gp_Identity) { | |
404 | shape = T.shape; | |
405 | scale = T.scale; | |
406 | loc = T.loc; | |
407 | matrix = T.matrix; | |
408 | } | |
409 | else if (shape == gp_Rotation && T.shape == gp_Rotation) { | |
410 | loc.Multiply (T.matrix); | |
411 | loc.Add (T.loc); | |
412 | matrix.PreMultiply(T.matrix); | |
413 | } | |
414 | else if (shape == gp_Translation && T.shape == gp_Translation) { | |
415 | loc.Add (T.loc); | |
416 | } | |
417 | else if (shape == gp_Scale && T.shape == gp_Scale) { | |
418 | loc.Multiply (T.scale); | |
419 | loc.Add (T.loc); | |
420 | scale = scale * T.scale; | |
421 | } | |
422 | else if (shape == gp_PntMirror && T.shape == gp_PntMirror) { | |
423 | scale = 1.0; | |
424 | shape = gp_Translation; | |
425 | loc.Reverse(); | |
426 | loc.Add (T.loc); | |
427 | } | |
428 | else if (shape == gp_Ax1Mirror && T.shape == gp_Ax1Mirror) { | |
429 | shape = gp_Rotation; | |
430 | loc.Multiply (T.matrix); | |
4714a7a6 SJ |
431 | loc.Multiply(T.scale); |
432 | scale = scale * T.scale; | |
7fd59977 | 433 | loc.Add (T.loc); |
434 | matrix.PreMultiply(T.matrix); | |
435 | } | |
436 | else if ((shape == gp_CompoundTrsf || shape == gp_Rotation || | |
437 | shape == gp_Ax1Mirror) && T.shape == gp_Translation) { | |
438 | loc.Add (T.loc); | |
439 | } | |
440 | else if ((shape == gp_Scale || shape == gp_PntMirror) | |
441 | && T.shape == gp_Translation) { | |
442 | loc.Add (T.loc); | |
443 | } | |
444 | else if (shape == gp_Translation && | |
445 | (T.shape == gp_CompoundTrsf || | |
446 | T.shape == gp_Rotation || T.shape == gp_Ax1Mirror)) { | |
447 | shape = gp_CompoundTrsf; | |
448 | matrix = T.matrix; | |
449 | if (T.scale == 1.0) loc.Multiply (T.matrix); | |
450 | else { | |
451 | scale = T.scale; | |
452 | loc.Multiply (matrix); | |
453 | loc.Multiply (scale); | |
454 | } | |
455 | loc.Add (T.loc); | |
456 | } | |
457 | else if ((T.shape == gp_Scale || T.shape == gp_PntMirror) | |
458 | && shape == gp_Translation) { | |
459 | loc.Multiply (T.scale); | |
460 | loc.Add (T.loc); | |
461 | scale = T.scale; | |
462 | shape = T.shape; | |
463 | } | |
464 | else if ((shape == gp_PntMirror || shape == gp_Scale) && | |
465 | (T.shape == gp_PntMirror || T.shape == gp_Scale)) { | |
466 | shape = gp_CompoundTrsf; | |
467 | loc.Multiply (T.scale); | |
468 | loc.Add (T.loc); | |
469 | scale = scale * T.scale; | |
470 | } | |
471 | else if ((shape == gp_CompoundTrsf || shape == gp_Rotation || | |
472 | shape == gp_Ax1Mirror) | |
473 | && (T.shape == gp_Scale || T.shape == gp_PntMirror)) { | |
474 | shape = gp_CompoundTrsf; | |
475 | loc.Multiply (T.scale); | |
476 | loc.Add (T.loc); | |
477 | scale = scale * T.scale; | |
478 | } | |
479 | else if ((T.shape == gp_CompoundTrsf || T.shape == gp_Rotation || | |
480 | T.shape == gp_Ax1Mirror) | |
481 | && (shape == gp_Scale || shape == gp_PntMirror)) { | |
482 | shape = gp_CompoundTrsf; | |
483 | matrix = T.matrix; | |
484 | if (T.scale == 1.0) loc.Multiply (T.matrix); | |
485 | else { | |
486 | loc.Multiply (matrix); | |
487 | loc.Multiply (T.scale); | |
488 | scale = T.scale * scale; | |
489 | } | |
490 | loc.Add (T.loc); | |
491 | } | |
492 | else { | |
493 | shape = gp_CompoundTrsf; | |
494 | loc.Multiply (T.matrix); | |
495 | if (T.scale != 1.0) { | |
496 | loc.Multiply(T.scale); scale = scale * T.scale; | |
497 | } | |
498 | loc.Add (T.loc); | |
499 | matrix.PreMultiply(T.matrix); | |
500 | } | |
501 | } | |
502 | ||
7a8c6a36 | 503 | //======================================================================= |
504 | //function : SetValues | |
505 | //purpose : | |
506 | //======================================================================= | |
507 | void gp_Trsf2d::SetValues(const Standard_Real a11, | |
508 | const Standard_Real a12, | |
509 | const Standard_Real a13, | |
510 | const Standard_Real a21, | |
511 | const Standard_Real a22, | |
512 | const Standard_Real a23) | |
513 | { | |
514 | gp_XY col1(a11,a21); | |
515 | gp_XY col2(a12,a22); | |
516 | gp_XY col3(a13,a23); | |
517 | // compute the determinant | |
518 | gp_Mat2d M(col1,col2); | |
519 | Standard_Real s = M.Determinant(); | |
520 | Standard_Real As = s; | |
521 | if (As < 0) | |
522 | As = - As; | |
523 | Standard_ConstructionError_Raise_if | |
524 | (As < gp::Resolution(),"gp_Trsf2d::SetValues, null determinant"); | |
525 | ||
526 | if (s > 0) | |
527 | s = sqrt(s); | |
528 | else | |
529 | s = sqrt(-s); | |
530 | ||
531 | M.Divide(s); | |
532 | ||
533 | scale = s; | |
534 | shape = gp_CompoundTrsf; | |
535 | ||
536 | matrix = M; | |
537 | Orthogonalize(); | |
538 | ||
539 | loc = col3; | |
540 | } | |
541 | ||
542 | ||
543 | //======================================================================= | |
544 | //function : Orthogonalize | |
545 | //purpose : | |
546 | //======================================================================= | |
547 | void gp_Trsf2d::Orthogonalize() | |
548 | { | |
549 | gp_Mat2d aTM(matrix); | |
550 | ||
551 | gp_XY aV1 = aTM.Column(1); | |
552 | gp_XY aV2 = aTM.Column(2); | |
553 | ||
554 | aV1.Normalize(); | |
555 | ||
556 | aV2 -= aV1*(aV2.Dot(aV1)); | |
557 | aV2.Normalize(); | |
558 | ||
559 | aTM.SetCols(aV1, aV2); | |
560 | ||
561 | aV1 = aTM.Row(1); | |
562 | aV2 = aTM.Row(2); | |
563 | ||
564 | aV1.Normalize(); | |
565 | ||
566 | aV2 -= aV1*(aV2.Dot(aV1)); | |
567 | aV2.Normalize(); | |
568 | ||
569 | aTM.SetRows(aV1, aV2); | |
570 | ||
571 | matrix = aTM; | |
572 | } |