Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / blocFissure / gmu / rotTrans.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2022  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 """Opérateur de rotation translation d'un objet centré à l'origine"""
21
22 import logging
23 import math
24
25 from .geomsmesh import geompy
26 from .geomsmesh import geomPublish
27
28 from . import initLog
29
30 from .triedreBase import triedreBase
31
32 O, OX, OY, OZ = triedreBase()
33
34 def rotTrans(objet, orientation, point, normal, trace = False):
35   """
36   Déplacement par rotation translation d'un objet centré à l'origine, vers un point de la surface de la pièce saine
37   dans laquelle on insère le défaut.
38   @param objet : objet original centré à l'origine (geomObject)
39   @param orientation : rotation selon OX de l'objet original (degrés)
40   @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
41   @param normal : la normale à la surface de la pièce saine au point central (geomObject)
42   @return trans : objet transformé (geomObject)
43   """
44   logging.info("start")
45
46   planXY = geompy.MakePlaneLCS(None, 2000, 1)
47   projXY = geompy.MakeProjection(normal, planXY)
48
49   [v_1,v_2] = geompy.ExtractShapes(projXY, geompy.ShapeType["VERTEX"], False)
50   xyz1 = geompy.PointCoordinates(v_1)
51   xyz2 = geompy.PointCoordinates(v_2)
52   x = xyz2[0] - xyz1[0]
53   y = xyz2[1] - xyz1[1]
54   sinalpha = y / math.sqrt(x*x + y*y)
55   cosalpha = x / math.sqrt(x*x + y*y)
56   alpha = math.asin(sinalpha)
57   if ( cosalpha < 0. ):
58     alpha = math.pi -alpha
59
60   beta = geompy.GetAngleRadians(OZ, normal)
61   [v_1,v_2] = geompy.ExtractShapes(normal, geompy.ShapeType["VERTEX"], False)
62   xyz1 = geompy.PointCoordinates(v_1)
63   xyz2 = geompy.PointCoordinates(v_2)
64   if ( (xyz2[2] - xyz1[2]) < 0 ):
65     beta = math.pi -beta
66
67   rot0 = geompy.MakeRotation(objet, OX, orientation*math.pi/180.0)
68   rot1 = geompy.MakeRotation(rot0, OZ, alpha)
69   axe2 = geompy.MakeRotation(OY, OZ, alpha)
70   rot2 = geompy.MakeRotation(rot1, axe2, beta -math.pi/2.)
71   logging.debug("alpha %f",alpha)
72   logging.debug("beta %f",beta)
73   if trace:
74     geomPublish(initLog.debug,  rot1, 'rot1' )
75     geomPublish(initLog.debug,  axe2, 'axe2' )
76     geomPublish(initLog.debug,  rot2, 'rot2' )
77
78   xyz = geompy.PointCoordinates(point)
79   trans = geompy.MakeTranslation(rot2, xyz[0], xyz[1], xyz[2])
80
81   return trans