From 3c53f52f60bf185d76c043566819b9c17ed8ccdf Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Tue, 6 Apr 2010 15:00:19 +0000 Subject: [PATCH] fix in revolution primitive (orientation of spline curve) --- libsrc/csg/revolution.cpp | 16 ++++++---------- libsrc/geom2d/spline.hpp | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/libsrc/csg/revolution.cpp b/libsrc/csg/revolution.cpp index 3e7da3ca..89863b6d 100644 --- a/libsrc/csg/revolution.cpp +++ b/libsrc/csg/revolution.cpp @@ -441,24 +441,20 @@ namespace netgen int n = int(2.*facets) + 1; - int i,j; - double phi; - Point<3> p; - - for(i=0; i<=n; i++) + for(int i=0; i<=n; i++) { Point<2> sp = spline->GetPoint(double(i)/double(n)); - for(j=0; j<=n; j++) + for(int j=0; j<=n; j++) { - phi = 2.*M_PI*double(j)/double(n); + double phi = 2.*M_PI*double(j)/double(n); - p = p0 + sp(0)*v_axis + sp(1)*cos(phi)*v1 + sp(1)*sin(phi)*v2; + Point<3> p = p0 + sp(0)*v_axis + sp(1)*cos(phi)*v1 + sp(1)*sin(phi)*v2; tas.AddPoint(p); } } - for(i=0; i SplineSeg3 :: GetTangent (const double t) const template void SplineSeg3 :: GetCoeff (Vector & u) const { - Point p; DenseMatrix a(6, 6); DenseMatrix ata(6, 6); Vector f(6); @@ -622,7 +621,7 @@ void SplineSeg3 :: GetCoeff (Vector & u) const double t = 0; for (int i = 0; i < 5; i++, t += 0.25) { - p = GetPoint (t); + Point p = GetPoint (t); a(i, 0) = p(0) * p(0); a(i, 1) = p(1) * p(1); a(i, 2) = p(0) * p(1); @@ -638,6 +637,17 @@ void SplineSeg3 :: GetCoeff (Vector & u) const u(5) = 1; a.MultTrans (u, f); ata.Solve (f, u); + + // the sign + Point p0 = GetPoint(0); + Vec ht = GetTangent(0); + Vec<2> tang(ht(0), ht(1)); + + double gradx = 2.*u(0)*p0(0) + u(2)*p0(1) + u(3); + double grady = 2.*u(1)*p0(1) + u(2)*p0(0) + u(4); + Vec<2> gradn (grady, -gradx); + + if (tang * gradn < 0) u *= -1; } /*