//-- IntAna_IntLinTorus.cxx //-- lbr : la methode avec les coefficients est catastrophique. //-- Mise en place d'une vraie solution. #include #include #include #include #include #include #include #include IntAna_IntLinTorus::IntAna_IntLinTorus () : done(Standard_False) {} IntAna_IntLinTorus::IntAna_IntLinTorus (const gp_Lin& L, const gp_Torus& T) { Perform(L,T); } void IntAna_IntLinTorus::Perform (const gp_Lin& L, const gp_Torus& T) { gp_Pnt PL=L.Location(); gp_Dir DL=L.Direction(); // Reparametrize the line: // set its location as nearest to the location of torus gp_Pnt TorLoc = T.Location(); Standard_Real ParamOfNewPL = gp_Vec(PL, TorLoc).Dot(gp_Vec(DL)); gp_Pnt NewPL( PL.XYZ() + ParamOfNewPL * DL.XYZ() ); //-------------------------------------------------------------- //-- Coefficients de la ligne dans le repere du cone //-- gp_Trsf trsf; trsf.SetTransformation(T.Position()); NewPL.Transform(trsf); DL.Transform(trsf); Standard_Real a,b,c,x1,y1,z1,x0,y0,z0; Standard_Real a0,a1,a2,a3,a4; Standard_Real R,r,R2,r2; x1 = DL.X(); y1 = DL.Y(); z1 = DL.Z(); x0 = NewPL.X(); y0 = NewPL.Y(); z0 = NewPL.Z(); R = T.MajorRadius(); R2 = R*R; r = T.MinorRadius(); r2 = r*r; a = x1*x1+y1*y1+z1*z1; b = 2.0*(x1*x0+y1*y0+z1*z0); c = x0*x0+y0*y0+z0*z0 - (R2+r2); a4 = a*a; a3 = 2.0*a*b; a2 = 2.0*a*c+4.0*R2*z1*z1+b*b; a1 = 2.0*b*c+8.0*R2*z1*z0; a0 = c*c+4.0*R2*(z0*z0-r2); Standard_Real u,v; math_DirectPolynomialRoots mdpr(a4,a3,a2,a1,a0); if(mdpr.IsDone()) { Standard_Integer nbsolvalid = 0; Standard_Integer n = mdpr.NbSolutions(); for(Standard_Integer i = 1; i<=n ; i++) { Standard_Real t = mdpr.Value(i); t += ParamOfNewPL; gp_Pnt PSolL(ElCLib::Value(t,L)); ElSLib::Parameters(T,PSolL,u,v); gp_Pnt PSolT(ElSLib::Value(u,v,T)); a0 = PSolT.SquareDistance(PSolL); if(a0>0.0000000001) { #if 0 cout<<" ------- Erreur : P Ligne < > P Tore "<0.0000000001) { cout<<" ------- Erreur : P Ligne < > P Tore "; cout<<"Ligne : X:"<