1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2022 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 """Projection d'un point sur une courbe."""
24 from .geomsmesh import geompy
26 def projettePointSurCourbe(point, edge):
28 projection d'un point p sur une courbe c
29 on suppose que la distance (c(u), p) passe par un minimum quand u varie entre 0 et 1
30 et qu'elle presente pas de minimum local
32 #logging.debug("start")
36 delta = 1.0/float(nb_slices)
37 for i_aux in range(nb_slices + 1):
38 pti = geompy.MakeVertexOnCurve(edge, delta*float(i_aux))
39 dpti = geompy.MinDistance(pti,point)
40 dist.append((dpti,i_aux))
43 #logging.debug("dist %s", dist)
44 umin = delta*dist[0][1]
45 umax = delta*dist[1][1]
49 pmin = geompy.MakeVertexOnCurve(edge, umin)
50 pmax = geompy.MakeVertexOnCurve(edge, umax)
51 dmin = geompy.MinDistance(pmin,point)
52 dmax = geompy.MinDistance(pmax,point)
53 dext = geompy.MinDistance(pmin,pmax)
55 while ( ( dext > tol ) and ( i_aux < 100 ) ):
57 utest = (umax + umin) / 2.0
58 ptest = geompy.MakeVertexOnCurve(edge, utest)
59 dtest = geompy.MinDistance(ptest,point)
68 dext = geompy.MinDistance(pmin,pmax)
69 #logging.debug('umin=%s umax=%s dmin=%s dmax=%s dtest=%s dext=%s', umin,umax,dmin,dmax,dtest,dext)
71 if ( abs(utest) < 1.e-7 ):
73 elif ( abs(1.0-utest) < 1.e-7 ):
75 logging.debug('u=%s, nbiter=%s dtest=%s dext=%s',utest,i_aux,dtest,dext)