1 # -*- coding: utf-8 -*-
3 from .geomsmesh import geompy
7 # -----------------------------------------------------------------------------
8 # --- projection d'un point sur une courbe.
10 def projettePointSurCourbe(pt, edge):
12 projection d'un point p sur une courbe c
13 on suppose que la distance (c(u), p) passe par un minimum quand u varie entre 0 et 1
14 et qu'elle presente pas de minimum local
16 #logging.debug("start")
21 for i in range(nbSlices + 1):
22 p = geompy.MakeVertexOnCurve(edge, du*i)
23 d = geompy.MinDistance(p,pt)
26 #logging.debug("dist %s", dist)
32 pmin = geompy.MakeVertexOnCurve(edge, umin)
33 pmax = geompy.MakeVertexOnCurve(edge, umax)
34 dmin = geompy.MinDistance(pmin,pt)
35 dmax = geompy.MinDistance(pmax,pt)
36 dext = geompy.MinDistance(pmin,pmax)
38 while dext > tol and i < 100 :
40 utest = (umax + umin) / 2.0
41 ptest = geompy.MakeVertexOnCurve(edge, utest)
42 dtest = geompy.MinDistance(ptest,pt)
51 dext = geompy.MinDistance(pmin,pmax)
52 #logging.debug('umin=%s umax=%s dmin=%s dmax=%s dtest=%s dext=%s', umin,umax,dmin,dmax,dtest,dext)
53 if abs(utest) < 1.e-7:
55 if abs(1.0-utest) < 1.e-7:
57 logging.debug('u=%s, nbiter=%s dtest=%s dext=%s',utest,i,dtest,dext)