Salome HOME
Copyright update 2020
[modules/smesh.git] / src / Tools / blocFissure / gmu / rotTrans.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import logging
22 from .geomsmesh import geompy
23 from .geomsmesh import geomPublish
24 from .geomsmesh import geomPublishInFather
25 from . import initLog
26 import math
27 from .triedreBase import triedreBase
28 O, OX, OY, OZ = triedreBase()
29
30 # -----------------------------------------------------------------------------
31 # --- operateur de rotation translation d'un objet centré à l'origine
32
33 def rotTrans(objet, orientation, point, normal, trace = False):
34   """
35   Déplacement par rotation translation d'un objet centré à l'origine, vers un point de la surface de la pièce saine
36   dans laquelle on insère le défaut.
37   @param objet : objet original centré à l'origine (geomObject)
38   @param orientation : rotation selon OX de l'objet original (degrés)
39   @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
40   @param normal : la normale à la surface de la pièce saine au point central (geomObject)
41   @return trans : objet transformé (geomObject)
42   """
43   logging.info("start")
44   planXY = geompy.MakePlaneLCS(None, 2000, 1)
45   projXY = geompy.MakeProjection(normal, planXY)
46   [v1,v2] = geompy.ExtractShapes(projXY, geompy.ShapeType["VERTEX"], False)
47   xyz1 = geompy.PointCoordinates(v1)
48   xyz2 = geompy.PointCoordinates(v2)
49   x = xyz2[0] - xyz1[0]
50   y = xyz2[1] - xyz1[1]
51   sinalpha = y / math.sqrt(x*x + y*y)
52   cosalpha = x / math.sqrt(x*x + y*y)
53   alpha = math.asin(sinalpha)
54   if cosalpha < 0:
55     alpha = math.pi -alpha
56
57   beta = geompy.GetAngleRadians(OZ, normal)
58   [v1,v2] = geompy.ExtractShapes(normal, geompy.ShapeType["VERTEX"], False)
59   xyz1 = geompy.PointCoordinates(v1)
60   xyz2 = geompy.PointCoordinates(v2)
61   z = xyz2[2] - xyz1[2]
62   if z < 0:
63     beta = math.pi -beta
64
65   rot0 = geompy.MakeRotation(objet, OX, orientation*math.pi/180.0)
66   rot1 = geompy.MakeRotation(rot0, OZ, alpha)
67   axe2 = geompy.MakeRotation(OY, OZ, alpha)
68   rot2 = geompy.MakeRotation(rot1, axe2, beta -math.pi/2.)
69   logging.debug("alpha",alpha)
70   logging.debug("beta",beta)
71   if trace:
72     geomPublish(initLog.debug,  rot1, 'rot1' )
73     geomPublish(initLog.debug,  axe2, 'axe2' )
74     geomPublish(initLog.debug,  rot2, 'rot2' )
75
76   xyz = geompy.PointCoordinates(point)
77   trans = geompy.MakeTranslation(rot2, xyz[0], xyz[1], xyz[2])
78   return trans