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