1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2019 CEA/DEN, 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
22 from .geomsmesh import geompy
24 # -----------------------------------------------------------------------------
25 # --- calcul de la position d'une shape par rapport à une face (dessus, dessous, sur la surface même)
27 def whichSide(face, obj, tol = 1.e-3):
29 Position d'un objet par rapport a une face (non nécessairement plane).
30 L'objet est supposé situé entierement d'un coté de la face,
31 ou lui appartenant totalement (objets traversants non pris en compte)
32 renvoie 1 si 'objet est du coté de la normale à la face,
33 -1 de l'autre coté, 0 si il est sur la face
35 logging.debug('start')
37 logging.debug("shape info %s", geompy.ShapeInfo(obj))
38 nbEdges = geompy.NbShapes(obj, geompy.ShapeType["EDGE"]) # --- attention ! pour une seule edge presente, renvoie 2
39 logging.debug(" nbEdges %s", nbEdges)
40 nbFaces = geompy.NbShapes(obj, geompy.ShapeType["FACE"]) # --- attention ! pour une seule face presente, renvoie 2
41 logging.debug(" nbFaces %s", nbFaces)
42 vertices = geompy.ExtractShapes(obj, geompy.ShapeType["VERTEX"], False)
43 if nbEdges > 0 and nbFaces == 0: # --- edges
45 point = geompy.MakeVertexOnCurve(obj, 0.5)
46 vertices.append(point)
48 edges = geompy.ExtractShapes(obj, geompy.ShapeType["EDGE"], False)
50 point = geompy.MakeVertexOnCurve(anEdge, 0.5)
51 vertices.append(point)
52 elif nbFaces >0: # --- faces
54 point = geompy.MakeVertexOnSurface(obj, 0.5, 0.5)
55 vertices.append(point)
57 faces = geompy.ExtractShapes(obj, geompy.ShapeType["FACE"], False)
59 point = geompy.MakeVertexOnSurface(aFace, 0.5, 0.5)
60 vertices.append(point)
63 for vertex in vertices:
64 distance = geompy.MinDistance(vertex, face)
65 logging.debug(" distance %s", distance)
67 projection = geompy.MakeProjection(vertex, face)
68 normal = geompy.GetNormal(face, projection)
69 vect = geompy.MakeVector(projection, vertex)
70 angle = geompy.GetAngle(normal, vect)
71 logging.debug(" angle %s", angle)
76 logging.debug(" side %s", side)