1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """Opérateur de rotation translation d'un objet centré à l'origine"""
25 from .geomsmesh import geompy
26 from .geomsmesh import geomPublish
30 from .triedreBase import triedreBase
32 O, OX, OY, OZ = triedreBase()
34 def rotTrans(objet, orientation, point, normal, trace = False):
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)
46 planXY = geompy.MakePlaneLCS(None, 2000, 1)
47 projXY = geompy.MakeProjection(normal, planXY)
49 [v_1,v_2] = geompy.ExtractShapes(projXY, geompy.ShapeType["VERTEX"], False)
50 xyz1 = geompy.PointCoordinates(v_1)
51 xyz2 = geompy.PointCoordinates(v_2)
54 sinalpha = y / math.sqrt(x*x + y*y)
55 cosalpha = x / math.sqrt(x*x + y*y)
56 alpha = math.asin(sinalpha)
58 alpha = math.pi -alpha
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 ):
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)
74 geomPublish(initLog.debug, rot1, 'rot1' )
75 geomPublish(initLog.debug, axe2, 'axe2' )
76 geomPublish(initLog.debug, rot2, 'rot2' )
78 xyz = geompy.PointCoordinates(point)
79 trans = geompy.MakeTranslation(rot2, xyz[0], xyz[1], xyz[2])