From 3c28f8f39a472fee2ecd0fd4608f7daf63136159 Mon Sep 17 00:00:00 2001 From: Thomas Toulorge <thomas.toulorge@mines-paristech.fr> Date: Wed, 9 Jan 2013 03:10:33 +0000 Subject: [PATCH] Improved inversion of parametrization (XYZtoUV) on GFace --- Geo/GFace.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp index ef02713b92..6dcb922de7 100644 --- a/Geo/GFace.cpp +++ b/Geo/GFace.cpp @@ -799,8 +799,8 @@ void GFace::XYZtoUV(double X, double Y, double Z, double &U, double &V, int iter; double mat[3][3], jac[3][3]; double umin, umax, vmin, vmax; - double initu[NumInitGuess] = {0.487, 0.6, 0.4, 0.7, 0.3, 0.8, 0.2, 1., 0., 0., 1.}; - double initv[NumInitGuess] = {0.487, 0.6, 0.4, 0.7, 0.3, 0.8, 0.2, 0., 1., 0., 1.}; + double initu[NumInitGuess] = {0.5, 0.6, 0.4, 0.7, 0.3, 0.8, 0.2, 0.9, 0.1, 1., 0.}; + double initv[NumInitGuess] = {0.5, 0.6, 0.4, 0.7, 0.3, 0.8, 0.2, 0.9, 0.1, 1., 0.}; Range<double> ru = parBounds(0); Range<double> rv = parBounds(1); @@ -809,6 +809,12 @@ void GFace::XYZtoUV(double X, double Y, double Z, double &U, double &V, vmin = rv.low(); vmax = rv.high(); + const double tol = Precision*(SQU(umax-umin)+SQU(vmax-vmin)); + for(int i = 0; i < NumInitGuess; i++) { + initu[i] = umin + initu[i]*(umax-umin); + initv[i] = vmin + initv[i]*(vmax-vmin); + } + for(int i = 0; i < NumInitGuess; i++){ for(int j = 0; j < NumInitGuess; j++){ @@ -821,7 +827,7 @@ void GFace::XYZtoUV(double X, double Y, double Z, double &U, double &V, err2 = sqrt(SQU(X - P.x()) + SQU(Y - P.y()) + SQU(Z - P.z())); if (err2 < 1.e-8 * CTX::instance()->lc) return; - while(err > Precision && iter < MaxIter) { + while(err > tol && iter < MaxIter) { P = point(U, V); Pair<SVector3, SVector3> der = firstDer(SPoint2(U, V)); mat[0][0] = der.left().x(); @@ -851,7 +857,7 @@ void GFace::XYZtoUV(double X, double Y, double Z, double &U, double &V, V = Vnew; } - if(iter < MaxIter && err <= Precision && + if(iter < MaxIter && err <= tol && Unew <= umax && Vnew <= vmax && Unew >= umin && Vnew >= vmin){ if (onSurface && err2 > 1.e-4 * CTX::instance()->lc) -- GitLab