Salome HOME
Merge branch V7_3_1_BR
[modules/smesh.git] / src / Tools / blocFissure / gmu / rotTrans.py
1 # -*- coding: utf-8 -*-
2
3 import logging
4 from geomsmesh import geompy
5 import math
6 from triedreBase import triedreBase
7 O, OX, OY, OZ = triedreBase()
8
9 # -----------------------------------------------------------------------------
10 # --- operateur de rotation translation d'un objet centré à l'origine
11
12 def rotTrans(objet, orientation, point, normal, trace = False):
13   """
14   Déplacement par rotation translation d'un objet centré à l'origine, vers un point de la surface de la pièce saine
15   dans laquelle on insère le défaut.
16   @param objet : objet original centré à l'origine (geomObject)
17   @param orientation : rotation selon OX de l'objet original (degrés)
18   @param point : le point qui sera le centre de l'objet déplacé (geomObject), en général sur la surface de la pièce saine
19   @param normal : la normale à la surface de la pièce saine au point central (geomObject)
20   @return trans : objet transformé (geomObject)
21   """
22   logging.info("start")
23   planXY = geompy.MakePlaneLCS(None, 2000, 1)
24   projXY = geompy.MakeProjection(normal, planXY)
25   [v1,v2] = geompy.ExtractShapes(projXY, geompy.ShapeType["VERTEX"], False)
26   xyz1 = geompy.PointCoordinates(v1)
27   xyz2 = geompy.PointCoordinates(v2)
28   x = xyz2[0] - xyz1[0]
29   y = xyz2[1] - xyz1[1]
30   sinalpha = y / math.sqrt(x*x + y*y)
31   cosalpha = x / math.sqrt(x*x + y*y)
32   alpha = math.asin(sinalpha)
33   if cosalpha < 0:
34     alpha = math.pi -alpha
35
36   beta = geompy.GetAngleRadians(OZ, normal)
37   [v1,v2] = geompy.ExtractShapes(normal, geompy.ShapeType["VERTEX"], False)
38   xyz1 = geompy.PointCoordinates(v1)
39   xyz2 = geompy.PointCoordinates(v2)
40   z = xyz2[2] - xyz1[2]
41   if z < 0:
42     beta = math.pi -beta
43
44   rot0 = geompy.MakeRotation(objet, OX, orientation*math.pi/180.0)
45   rot1 = geompy.MakeRotation(rot0, OZ, alpha)
46   axe2 = geompy.MakeRotation(OY, OZ, alpha)
47   rot2 = geompy.MakeRotation(rot1, axe2, beta -math.pi/2.)
48   logging.debug("alpha",alpha)
49   logging.debug("beta",beta)
50   if trace:
51     geompy.addToStudy( rot1, 'rot1' )
52     geompy.addToStudy( axe2, 'axe2' )
53     geompy.addToStudy( rot2, 'rot2' )
54
55   xyz = geompy.PointCoordinates(point)
56   trans = geompy.MakeTranslation(rot2, xyz[0], xyz[1], xyz[2])
57   return trans