1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020 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
21 from .geomsmesh import geompy
25 # -----------------------------------------------------------------------------
26 # --- projection d'un point sur une courbe.
28 def projettePointSurCourbe(pt, edge):
30 projection d'un point p sur une courbe c
31 on suppose que la distance (c(u), p) passe par un minimum quand u varie entre 0 et 1
32 et qu'elle presente pas de minimum local
34 #logging.debug("start")
39 for i in range(nbSlices + 1):
40 p = geompy.MakeVertexOnCurve(edge, du*i)
41 d = geompy.MinDistance(p,pt)
44 #logging.debug("dist %s", dist)
50 pmin = geompy.MakeVertexOnCurve(edge, umin)
51 pmax = geompy.MakeVertexOnCurve(edge, umax)
52 dmin = geompy.MinDistance(pmin,pt)
53 dmax = geompy.MinDistance(pmax,pt)
54 dext = geompy.MinDistance(pmin,pmax)
56 while dext > tol and i < 100 :
58 utest = (umax + umin) / 2.0
59 ptest = geompy.MakeVertexOnCurve(edge, utest)
60 dtest = geompy.MinDistance(ptest,pt)
69 dext = geompy.MinDistance(pmin,pmax)
70 #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 if abs(1.0-utest) < 1.e-7:
75 logging.debug('u=%s, nbiter=%s dtest=%s dext=%s',utest,i,dtest,dext)