2014-01-09 14:20:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-03-23 17:44:27 +03:00
|
|
|
# Copyright (C) 2014-2021 EDF R&D
|
2019-02-14 14:55:47 +03:00
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
|
|
|
#
|
2021-04-02 13:17:18 +02:00
|
|
|
"""Opérateur de rotation translation d'un objet centré à l'origine"""
|
2014-01-09 14:20:44 +00:00
|
|
|
|
|
|
|
import logging
|
2021-04-02 13:17:18 +02:00
|
|
|
import math
|
|
|
|
|
2017-03-20 13:27:30 +01:00
|
|
|
from .geomsmesh import geompy
|
|
|
|
from .geomsmesh import geomPublish
|
2021-04-02 13:17:18 +02:00
|
|
|
|
2017-03-20 13:27:30 +01:00
|
|
|
from . import initLog
|
2021-04-02 13:17:18 +02:00
|
|
|
|
2017-03-20 13:27:30 +01:00
|
|
|
from .triedreBase import triedreBase
|
2014-01-09 14:20:44 +00:00
|
|
|
|
2021-04-02 13:17:18 +02:00
|
|
|
O, OX, OY, OZ = triedreBase()
|
2014-01-09 14:20:44 +00:00
|
|
|
|
|
|
|
def rotTrans(objet, orientation, point, normal, trace = False):
|
|
|
|
"""
|
|
|
|
Déplacement par rotation translation d'un objet centré à l'origine, vers un point de la surface de la pièce saine
|
|
|
|
dans laquelle on insère le défaut.
|
|
|
|
@param objet : objet original centré à l'origine (geomObject)
|
|
|
|
@param orientation : rotation selon OX de l'objet original (degrés)
|
|
|
|
@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
|
|
|
|
@param normal : la normale à la surface de la pièce saine au point central (geomObject)
|
|
|
|
@return trans : objet transformé (geomObject)
|
|
|
|
"""
|
|
|
|
logging.info("start")
|
2021-04-02 13:17:18 +02:00
|
|
|
|
2014-01-09 14:20:44 +00:00
|
|
|
planXY = geompy.MakePlaneLCS(None, 2000, 1)
|
|
|
|
projXY = geompy.MakeProjection(normal, planXY)
|
2021-04-02 13:17:18 +02:00
|
|
|
|
|
|
|
[v_1,v_2] = geompy.ExtractShapes(projXY, geompy.ShapeType["VERTEX"], False)
|
|
|
|
xyz1 = geompy.PointCoordinates(v_1)
|
|
|
|
xyz2 = geompy.PointCoordinates(v_2)
|
2014-01-09 14:20:44 +00:00
|
|
|
x = xyz2[0] - xyz1[0]
|
|
|
|
y = xyz2[1] - xyz1[1]
|
|
|
|
sinalpha = y / math.sqrt(x*x + y*y)
|
|
|
|
cosalpha = x / math.sqrt(x*x + y*y)
|
|
|
|
alpha = math.asin(sinalpha)
|
2021-04-02 13:17:18 +02:00
|
|
|
if ( cosalpha < 0. ):
|
2014-01-09 14:20:44 +00:00
|
|
|
alpha = math.pi -alpha
|
|
|
|
|
|
|
|
beta = geompy.GetAngleRadians(OZ, normal)
|
2021-04-02 13:17:18 +02:00
|
|
|
[v_1,v_2] = geompy.ExtractShapes(normal, geompy.ShapeType["VERTEX"], False)
|
|
|
|
xyz1 = geompy.PointCoordinates(v_1)
|
|
|
|
xyz2 = geompy.PointCoordinates(v_2)
|
|
|
|
if ( (xyz2[2] - xyz1[2]) < 0 ):
|
2014-01-09 14:20:44 +00:00
|
|
|
beta = math.pi -beta
|
|
|
|
|
|
|
|
rot0 = geompy.MakeRotation(objet, OX, orientation*math.pi/180.0)
|
|
|
|
rot1 = geompy.MakeRotation(rot0, OZ, alpha)
|
|
|
|
axe2 = geompy.MakeRotation(OY, OZ, alpha)
|
|
|
|
rot2 = geompy.MakeRotation(rot1, axe2, beta -math.pi/2.)
|
2021-04-02 13:17:18 +02:00
|
|
|
logging.debug("alpha %f",alpha)
|
|
|
|
logging.debug("beta %f",beta)
|
2014-01-09 14:20:44 +00:00
|
|
|
if trace:
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, rot1, 'rot1' )
|
|
|
|
geomPublish(initLog.debug, axe2, 'axe2' )
|
|
|
|
geomPublish(initLog.debug, rot2, 'rot2' )
|
2014-01-09 14:20:44 +00:00
|
|
|
|
|
|
|
xyz = geompy.PointCoordinates(point)
|
|
|
|
trans = geompy.MakeTranslation(rot2, xyz[0], xyz[1], xyz[2])
|
2021-04-02 13:17:18 +02:00
|
|
|
|
2014-01-09 14:20:44 +00:00
|
|
|
return trans
|