1 // Created on: 1997-02-10
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_HCurve2d.hxx>
19 #include <Adaptor3d_HCurve.hxx>
20 #include <Adaptor3d_HSurface.hxx>
21 #include <Blend_Point.hxx>
22 #include <BlendFunc.hxx>
23 #include <BRepBlend_SurfRstConstRad.hxx>
25 #include <GeomFill.hxx>
27 #include <gp_Circ.hxx>
29 #include <gp_Pnt2d.hxx>
31 #include <gp_Vec2d.hxx>
32 #include <math_Gauss.hxx>
33 #include <math_Matrix.hxx>
34 #include <math_SVD.hxx>
35 #include <Precision.hxx>
36 #include <Standard_DomainError.hxx>
37 #include <Standard_NotImplemented.hxx>
41 static void t3dto2d(Standard_Real& a,
47 Standard_Real AB = A.Dot(B);
48 Standard_Real AC = A.Dot(C);
49 Standard_Real BC = B.Dot(C);
50 Standard_Real BB = B.Dot(B);
51 Standard_Real CC = C.Dot(C);
52 Standard_Real deno = (BB*CC-BC*BC);
53 a = (AB*CC-AC*BC)/deno;
54 b = (AC*BB-AB*BC)/deno;
57 //=======================================================================
58 //function : BRepBlend_SurfRstConstRad
60 //=======================================================================
62 BRepBlend_SurfRstConstRad::BRepBlend_SurfRstConstRad
63 (const Handle(Adaptor3d_HSurface)& Surf,
64 const Handle(Adaptor3d_HSurface)& SurfRst,
65 const Handle(Adaptor2d_HCurve2d)& Rst,
66 const Handle(Adaptor3d_HCurve)& CGuide):
67 surf(Surf), surfrst(SurfRst), rst(Rst), cons(Rst,SurfRst),
68 guide(CGuide), tguide(CGuide),
69 istangent(Standard_True), theD(0.), maxang(RealFirst()), minang(RealLast()),
71 mySShape(BlendFunc_Rational)
74 //=======================================================================
75 //function : NbVariables
77 //=======================================================================
79 Standard_Integer BRepBlend_SurfRstConstRad::NbVariables() const
84 //=======================================================================
85 //function : NbEquations
87 //=======================================================================
89 Standard_Integer BRepBlend_SurfRstConstRad::NbEquations() const
94 //=======================================================================
97 //=======================================================================
99 Standard_Boolean BRepBlend_SurfRstConstRad::Value(const math_Vector& X,
102 gp_Vec d1u1,d1v1,ns,vref;
105 surf->D1(X(1),X(2),pts,d1u1,d1v1);
106 ptrst = cons.Value(X(3));
108 F(1) = nplan.XYZ().Dot(pts.XYZ()) + theD;
109 F(2) = nplan.XYZ().Dot(ptrst.XYZ()) + theD;
111 ns = d1u1.Crossed(d1v1);
112 norm = nplan.Crossed(ns).Magnitude();
113 ns.SetLinearForm(nplan.Dot(ns)/norm,nplan, -1./norm,ns);
114 vref.SetLinearForm(ray,ns,gp_Vec(ptrst,pts));
116 F(3) = (vref.SquareMagnitude() - 1)*ray*ray;
117 return Standard_True;
120 //=======================================================================
121 //function : Derivatives
123 //=======================================================================
125 Standard_Boolean BRepBlend_SurfRstConstRad::Derivatives(const math_Vector& X,
128 gp_Vec d1u1,d1v1,d2u1,d2v1,d2uv1,d1;
129 gp_Vec ns,ncrossns,resul,temp, vref;
131 Standard_Real norm,ndotns,grosterme;
133 surf->D2(X(1),X(2),pts,d1u1,d1v1,d2u1,d2v1,d2uv1);
134 cons.D1(X(3),ptrst,d1);
136 D(1,1) = nplan.Dot(d1u1);
137 D(1,2) = nplan.Dot(d1v1);
142 D(2,3) = nplan.Dot(d1);
145 ns = d1u1.Crossed(d1v1);
146 ncrossns = nplan.Crossed(ns);
147 norm = ncrossns.Magnitude();
148 ndotns = nplan.Dot(ns);
150 vref.SetLinearForm(ndotns,nplan,-1.,ns);
152 vref.SetLinearForm(ray,vref,gp_Vec(ptrst,pts));
155 temp = d2u1.Crossed(d1v1).Added(d1u1.Crossed(d2uv1));
156 grosterme = ncrossns.Dot(nplan.Crossed(temp))/norm/norm;
157 resul.SetLinearForm(-ray/norm*(grosterme*ndotns-nplan.Dot(temp)),nplan,
158 ray*grosterme/norm,ns,
162 D(3,1) = resul.Dot(vref);
163 D(3,1) = D(3,1) * 2.;
167 temp = d2uv1.Crossed(d1v1).Added(d1u1.Crossed(d2v1));
168 grosterme = ncrossns.Dot(nplan.Crossed(temp))/norm/norm;
169 resul.SetLinearForm(-ray/norm*(grosterme*ndotns-nplan.Dot(temp)),nplan,
170 ray*grosterme/norm,ns,
174 D(3,2) = resul.Dot(vref);
175 D(3,2) = D(3,2) * 2.;
177 D(3,3) = d1.Dot(vref);
178 D(3,3) = D(3,3) * (-2.);
180 return Standard_True;
183 //=======================================================================
186 //=======================================================================
188 Standard_Boolean BRepBlend_SurfRstConstRad::Values(const math_Vector& X,
193 gp_Vec d2u1,d2v1,d2uv1;
194 gp_Vec ns,ncrossns,resul,temp,vref;
196 Standard_Real norm,ndotns,grosterme;
198 surf->D2(X(1),X(2),pts,d1u1,d1v1,d2u1,d2v1,d2uv1);
199 cons.D1(X(3),ptrst,d1);
201 F(1) = nplan.XYZ().Dot(pts.XYZ()) + theD;
202 F(2) = nplan.XYZ().Dot(ptrst.XYZ()) + theD;
204 D(1,1) = nplan.Dot(d1u1);
205 D(1,2) = nplan.Dot(d1v1);
210 D(2,3) = nplan.Dot(d1);
212 ns = d1u1.Crossed(d1v1);
213 ncrossns = nplan.Crossed(ns);
214 norm = ncrossns.Magnitude();
215 ndotns = nplan.Dot(ns);
217 vref.SetLinearForm(ndotns,nplan,-1.,ns);
219 vref.SetLinearForm(ray,vref,gp_Vec(ptrst,pts));
222 // F(3) = vref.SquareMagnitude() - ray*ray;
223 F(3) = (temp.SquareMagnitude() - 1)*ray*ray; // more stable numerically
226 temp = d2u1.Crossed(d1v1).Added(d1u1.Crossed(d2uv1));
227 grosterme = ncrossns.Dot(nplan.Crossed(temp))/norm/norm;
228 resul.SetLinearForm(-ray/norm*(grosterme*ndotns-nplan.Dot(temp)),nplan,
229 ray*grosterme/norm,ns,
233 D(3,1) = resul.Dot(vref);
239 temp = d2uv1.Crossed(d1v1).Added(d1u1.Crossed(d2v1));
240 grosterme = ncrossns.Dot(nplan.Crossed(temp))/norm/norm;
241 resul.SetLinearForm(-ray/norm*(grosterme*ndotns-nplan.Dot(temp)),nplan,
242 ray*grosterme/norm,ns,
246 D(3,2) = resul.Dot(vref);
249 D(3,3) = d1.Dot(vref);
250 D(3,3) = D(3,3)*(-2.);
252 return Standard_True;
255 //=======================================================================
258 //=======================================================================
260 void BRepBlend_SurfRstConstRad::Set(const Handle(Adaptor3d_HSurface)& SurfRef,
261 const Handle(Adaptor2d_HCurve2d)& RstRef)
267 //=======================================================================
270 //=======================================================================
272 void BRepBlend_SurfRstConstRad::Set(const Standard_Real Param)
274 d1gui = gp_Vec(0.,0.,0.);
275 nplan = gp_Vec(0.,0.,0.);
276 tguide->D2(Param,ptgui,d1gui,d2gui);
277 normtg = d1gui.Magnitude();
278 nplan.SetXYZ(d1gui.Normalized().XYZ());
279 gp_XYZ nplanXYZ(nplan.XYZ());
280 gp_XYZ ptguiXYZ(ptgui.XYZ());
281 theD = nplanXYZ.Dot(ptguiXYZ) ;
282 theD = theD * (-1.) ;
285 //=======================================================================
288 //=======================================================================
290 void BRepBlend_SurfRstConstRad::Set(const Standard_Real First,
291 const Standard_Real Last)
293 tguide = guide->Trim(First, Last, 1.e-12);
296 //=======================================================================
297 //function : GetTolerance
299 //=======================================================================
301 void BRepBlend_SurfRstConstRad::GetTolerance(math_Vector& Tolerance,
302 const Standard_Real Tol) const
304 Tolerance(1) = surf->UResolution(Tol);
305 Tolerance(2) = surf->VResolution(Tol);
306 Tolerance(3) = cons.Resolution(Tol);
309 //=======================================================================
310 //function : GetBounds
312 //=======================================================================
314 void BRepBlend_SurfRstConstRad::GetBounds(math_Vector& InfBound,
315 math_Vector& SupBound) const
317 InfBound(1) = surf->FirstUParameter();
318 InfBound(2) = surf->FirstVParameter();
319 InfBound(3) = cons.FirstParameter();
320 SupBound(1) = surf->LastUParameter();
321 SupBound(2) = surf->LastVParameter();
322 SupBound(3) = cons.LastParameter();
324 if(!Precision::IsInfinite(InfBound(1)) &&
325 !Precision::IsInfinite(SupBound(1))) {
326 Standard_Real range = (SupBound(1) - InfBound(1));
327 InfBound(1) -= range;
328 SupBound(1) += range;
330 if(!Precision::IsInfinite(InfBound(2)) &&
331 !Precision::IsInfinite(SupBound(2))) {
332 Standard_Real range = (SupBound(2) - InfBound(2));
333 InfBound(2) -= range;
334 SupBound(2) += range;
338 //=======================================================================
339 //function : IsSolution
341 //=======================================================================
343 Standard_Boolean BRepBlend_SurfRstConstRad::IsSolution(const math_Vector& Sol,
344 const Standard_Real Tol)
348 math_Vector valsol(1,3),secmember(1,3);
349 math_Matrix gradsol(1,3,1,3);
351 gp_Vec dnplan,d1u1,d1v1,d1urst,d1vrst,d1,temp,ns,ns2,ncrossns,resul;
353 Standard_Real norm,ndotns,grosterme;
354 Standard_Real Cosa,Sina,Angle;
356 Values(Sol,valsol,gradsol);
357 if (Abs(valsol(1)) <= Tol &&
358 Abs(valsol(2)) <= Tol &&
359 Abs(valsol(3)) <= 2*Tol*Abs(ray) ) {
361 // Calculation of tangents
363 pt2ds = gp_Pnt2d(Sol(1),Sol(2));
365 pt2drst = rst->Value(prmrst);
366 surf->D1(Sol(1),Sol(2),pts,d1u1,d1v1);
367 cons.D1(Sol(3),ptrst,d1);
368 dnplan.SetLinearForm(1./normtg,d2gui,
369 -1./normtg*(nplan.Dot(d2gui)),nplan);
371 temp.SetXYZ(pts.XYZ() - ptgui.XYZ());
372 secmember(1) = normtg - dnplan.Dot(temp);
374 temp.SetXYZ(ptrst.XYZ() - ptgui.XYZ());
375 secmember(2) = normtg - dnplan.Dot(temp);
377 ns = d1u1.Crossed(d1v1);
378 ncrossns = nplan.Crossed(ns);
379 ndotns = nplan.Dot(ns);
380 norm = ncrossns.Magnitude();
382 grosterme = ncrossns.Dot(dnplan.Crossed(ns))/norm/norm;
383 temp.SetLinearForm(ray/norm*(dnplan.Dot(ns)-grosterme*ndotns),nplan,
384 ray*ndotns/norm,dnplan,
385 ray*grosterme/norm,ns);
387 ns.SetLinearForm(ndotns/norm,nplan, -1./norm,ns);
388 resul.SetLinearForm(ray,ns,gp_Vec(ptrst,pts));
389 secmember(3) = -2.*(temp.Dot(resul));
391 math_Gauss Resol(gradsol);
392 if (Resol.IsDone()) {
393 Resol.Solve(secmember);
394 istangent = Standard_False;
397 math_SVD SingRS (gradsol);
398 if (SingRS.IsDone()) {
399 math_Vector DEDT(1,3);
401 SingRS.Solve(DEDT, secmember, 1.e-6);
402 istangent = Standard_False;
404 else istangent = Standard_True;
408 tgs.SetLinearForm(secmember(1),d1u1,secmember(2),d1v1);
409 tgrst = secmember(3)*d1;
410 tg2ds.SetCoord(secmember(1),secmember(2));
411 surfrst->D1(pt2drst.X(),pt2drst.Y(),bid,d1urst,d1vrst);
413 t3dto2d(a,b,tgrst,d1urst,d1vrst);
414 tg2drst.SetCoord(a,b);
418 if(ray>0.) ns.Reverse();
419 ns2 = -resul.Normalized();
422 Sina = nplan.Dot(ns.Crossed(ns2));
424 Sina = -Sina; //nplan is changed to -nplan
429 Angle = 2.*M_PI - Angle;
432 if (Angle>maxang) {maxang = Angle;}
433 if (Angle<minang) {minang = Angle;}
434 distmin = Min( distmin, pts.Distance(ptrst));
436 return Standard_True;
438 istangent = Standard_True;
439 return Standard_False;
442 //=======================================================================
443 //function : GetMinimalDistance
445 //=======================================================================
447 Standard_Real BRepBlend_SurfRstConstRad::GetMinimalDistance() const
452 //=======================================================================
453 //function : PointOnS
455 //=======================================================================
457 const gp_Pnt& BRepBlend_SurfRstConstRad::PointOnS() const
462 //=======================================================================
463 //function : PointOnRst
465 //=======================================================================
467 const gp_Pnt& BRepBlend_SurfRstConstRad::PointOnRst() const
472 //=======================================================================
473 //function : Pnt2dOnS
475 //=======================================================================
477 const gp_Pnt2d& BRepBlend_SurfRstConstRad::Pnt2dOnS() const
482 //=======================================================================
483 //function : Pnt2dOnRst
485 //=======================================================================
487 const gp_Pnt2d& BRepBlend_SurfRstConstRad::Pnt2dOnRst() const
492 //=======================================================================
493 //function : ParameterOnRst
495 //=======================================================================
497 Standard_Real BRepBlend_SurfRstConstRad::ParameterOnRst() const
502 //=======================================================================
503 //function : IsTangencyPoint
505 //=======================================================================
507 Standard_Boolean BRepBlend_SurfRstConstRad::IsTangencyPoint() const
512 //=======================================================================
513 //function : TangentOnS
515 //=======================================================================
517 const gp_Vec& BRepBlend_SurfRstConstRad::TangentOnS() const
519 if (istangent) {throw Standard_DomainError();}
523 //=======================================================================
524 //function : Tangent2dOnS
526 //=======================================================================
528 const gp_Vec2d& BRepBlend_SurfRstConstRad::Tangent2dOnS() const
530 if (istangent) {throw Standard_DomainError();}
534 //=======================================================================
535 //function : TangentOnRst
537 //=======================================================================
539 const gp_Vec& BRepBlend_SurfRstConstRad::TangentOnRst() const
541 if (istangent) {throw Standard_DomainError();}
545 //=======================================================================
546 //function : Tangent2dOnRst
548 //=======================================================================
550 const gp_Vec2d& BRepBlend_SurfRstConstRad::Tangent2dOnRst() const
552 if (istangent) {throw Standard_DomainError();}
556 //=======================================================================
559 //=======================================================================
561 Standard_Boolean BRepBlend_SurfRstConstRad::Decroch(const math_Vector& Sol,
565 gp_Vec TgRst, NRst, NRstInPlane, NSInPlane;
568 Standard_Real norm,unsurnorm;
570 surf->D1(Sol(1),Sol(2),bid,d1u,d1v);
571 NS = NSInPlane = d1u.Crossed(d1v);
573 norm = nplan.Crossed(NS).Magnitude();
575 NSInPlane.SetLinearForm(nplan.Dot(NS)*unsurnorm,nplan,-unsurnorm,NS);
577 Center.SetXYZ(bid.XYZ()+ray*NSInPlane.XYZ());
578 if(choix>2) NSInPlane.Reverse();
579 TgS = nplan.Crossed(gp_Vec(Center,bid));
584 rstref->Value(Sol(3)).Coord(u,v);
585 surfref->D1(u,v,bid,d1u,d1v);
586 NRst = d1u.Crossed(d1v);
587 norm = nplan.Crossed(NRst).Magnitude();
589 NRstInPlane.SetLinearForm(nplan.Dot(NRst)*unsurnorm,nplan,-unsurnorm,NRst);
590 gp_Vec centptrst(Center,bid);
591 if(centptrst.Dot(NRstInPlane) < 0.) NRstInPlane.Reverse();
592 TgRst = nplan.Crossed(centptrst);
597 Standard_Real dot, NT = NRstInPlane.Magnitude();
598 NT *= TgRst.Magnitude();
599 if (Abs(NT) < 1.e-7) {
600 return Standard_False; // Singularity or Incoherence.
602 dot = NRstInPlane.Dot(TgRst);
605 return (dot < 1.e-10);
608 //=======================================================================
611 //=======================================================================
613 void BRepBlend_SurfRstConstRad::Set(const Standard_Real Radius,
614 const Standard_Integer Choix)
632 //=======================================================================
635 //=======================================================================
637 void BRepBlend_SurfRstConstRad::Set(const BlendFunc_SectionShape TypeSection)
639 mySShape = TypeSection;
642 //=======================================================================
645 //=======================================================================
647 void BRepBlend_SurfRstConstRad::Section(const Standard_Real Param,
648 const Standard_Real U,
649 const Standard_Real V,
650 const Standard_Real W,
660 tguide->D1(Param,ptgui,d1gui);
661 np = d1gui.Normalized();
663 surf->D1(U,V,pts,d1u1,d1v1);
664 ptrst = cons.Value(W);
666 ns = d1u1.Crossed(d1v1);
668 norm = nplan.Crossed(ns).Magnitude();
669 ns.SetLinearForm(nplan.Dot(ns)/norm,nplan, -1./norm,ns);
670 Center.SetXYZ(pts.XYZ()+ray*ns.XYZ());
671 C.SetRadius(Abs(ray));
681 C.SetPosition(gp_Ax2(Center,np,ns));
682 Pdeb = 0; //ElCLib::Parameter(C,pts);
683 Pfin = ElCLib::Parameter(C,ptrst);
685 // Test negative and almost null angles : Special case
688 C.SetPosition(gp_Ax2(Center,np,ns));
689 Pfin = ElCLib::Parameter(C,ptrst);
691 if (Pfin < Precision::PConfusion()) Pfin += Precision::PConfusion();
694 //=======================================================================
695 //function : IsRational
697 //=======================================================================
699 Standard_Boolean BRepBlend_SurfRstConstRad::IsRational () const
701 return (mySShape==BlendFunc_Rational || mySShape==BlendFunc_QuasiAngular);
704 //=======================================================================
705 //function : GetSectionSize
707 //=======================================================================
709 Standard_Real BRepBlend_SurfRstConstRad::GetSectionSize() const
711 return maxang*Abs(ray);
714 //=======================================================================
715 //function : GetMinimalWeight
717 //=======================================================================
719 void BRepBlend_SurfRstConstRad::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
721 BlendFunc::GetMinimalWeights(mySShape, myTConv, minang, maxang, Weights );
722 // It is supposed that it does not depend on the Radius!
725 //=======================================================================
726 //function : NbIntervals
728 //=======================================================================
730 Standard_Integer BRepBlend_SurfRstConstRad::NbIntervals (const GeomAbs_Shape S) const
732 return guide->NbIntervals(BlendFunc::NextShape(S));
735 //=======================================================================
736 //function : Intervals
738 //=======================================================================
740 void BRepBlend_SurfRstConstRad::Intervals (TColStd_Array1OfReal& T,
741 const GeomAbs_Shape S) const
743 guide->Intervals(T, BlendFunc::NextShape(S));
746 //=======================================================================
747 //function : GetShape
749 //=======================================================================
751 void BRepBlend_SurfRstConstRad::GetShape (Standard_Integer& NbPoles,
752 Standard_Integer& NbKnots,
753 Standard_Integer& Degree,
754 Standard_Integer& NbPoles2d)
757 BlendFunc::GetShape(mySShape,maxang,NbPoles,NbKnots,Degree,myTConv);
760 //=======================================================================
761 //function : GetTolerance
762 //purpose : Find Tolerance to be used in approximations.
763 //=======================================================================
765 void BRepBlend_SurfRstConstRad::GetTolerance(const Standard_Real BoundTol,
766 const Standard_Real SurfTol,
767 const Standard_Real AngleTol,
769 math_Vector& Tol1d) const
771 Standard_Integer low = Tol3d.Lower() , up=Tol3d.Upper();
773 Tol= GeomFill::GetTolerance(myTConv, minang, Abs(ray),
777 Tol3d(low+1) = Tol3d(up-1) = Min( Tol, SurfTol);
778 Tol3d(low) = Tol3d(up) = Min( Tol, BoundTol);
781 //=======================================================================
784 //=======================================================================
786 void BRepBlend_SurfRstConstRad::Knots(TColStd_Array1OfReal& TKnots)
788 GeomFill::Knots(myTConv,TKnots);
791 //=======================================================================
794 //=======================================================================
796 void BRepBlend_SurfRstConstRad::Mults(TColStd_Array1OfInteger& TMults)
798 GeomFill::Mults(myTConv, TMults);
801 //=======================================================================
804 //=======================================================================
806 void BRepBlend_SurfRstConstRad::Section(const Blend_Point& P,
807 TColgp_Array1OfPnt& Poles,
808 TColgp_Array1OfPnt2d& Poles2d,
809 TColStd_Array1OfReal& Weights)
811 gp_Vec d1u1,d1v1;//,,d1;
812 gp_Vec ns,ns2;//,temp,np2;
815 Standard_Real norm,u1,v1,w;
817 Standard_Real prm = P.Parameter();
818 Standard_Integer low = Poles.Lower();
819 Standard_Integer upp = Poles.Upper();
821 tguide->D1(prm,ptgui,d1gui);
822 nplan = d1gui.Normalized();
824 P.ParametersOnS(u1,v1);
825 w = P.ParameterOnC(); //jlr : point on curve not on surface
826 gp_Pnt2d pt2d = rst->Value(w);
828 surf->D1(u1,v1,pts,d1u1,d1v1);
829 ptrst = cons.Value(w);
830 distmin = Min (distmin, pts.Distance(ptrst));
832 Poles2d(Poles2d.Lower()).SetCoord(u1,v1);
833 Poles2d(Poles2d.Upper()).SetCoord(pt2d.X(),pt2d.Y());
836 if (mySShape == BlendFunc_Linear) {
844 ns = d1u1.Crossed(d1v1);
845 norm = nplan.Crossed(ns).Magnitude();
847 ns.SetLinearForm(nplan.Dot(ns)/norm,nplan, -1./norm,ns);
849 Center.SetXYZ(pts.XYZ()+ray*ns.XYZ());
851 ns2 = gp_Vec(Center,ptrst).Normalized();
852 if(ray>0) ns.Reverse();
857 GeomFill::GetCircle(myTConv,
864 //=======================================================================
867 //=======================================================================
869 Standard_Boolean BRepBlend_SurfRstConstRad::Section
870 (const Blend_Point& P,
871 TColgp_Array1OfPnt& Poles,
872 TColgp_Array1OfVec& DPoles,
873 TColgp_Array1OfPnt2d& Poles2d,
874 TColgp_Array1OfVec2d& DPoles2d,
875 TColStd_Array1OfReal& Weights,
876 TColStd_Array1OfReal& DWeights)
879 gp_Vec d1u1,d1v1,d2u1,d2v1,d2uv1,d1;
880 gp_Vec ns,ns2,dnplan,dnw,dn2w; //,np2,dnp2;
882 gp_Vec resulu,resulv,temp,tgct,resul;
883 gp_Vec d1urst,d1vrst;
886 Standard_Real norm,ndotns,grosterme;
888 math_Vector sol(1,3),valsol(1,3),secmember(1,3);
889 math_Matrix gradsol(1,3,1,3);
891 Standard_Real prm = P.Parameter();
892 Standard_Integer low = Poles.Lower();
893 Standard_Integer upp = Poles.Upper();
894 Standard_Boolean istgt;
896 tguide->D2(prm,ptgui,d1gui,d2gui);
897 normtg = d1gui.Magnitude();
898 nplan = d1gui.Normalized();
899 dnplan.SetLinearForm(1./normtg,d2gui,
900 -1./normtg*(nplan.Dot(d2gui)),nplan);
902 P.ParametersOnS(sol(1),sol(2));
903 sol(3) = prmrst = P.ParameterOnC();
904 pt2drst = rst->Value(prmrst);
906 Values(sol,valsol,gradsol);
908 surf->D2(sol(1),sol(2),pts,d1u1,d1v1,d2u1,d2v1,d2uv1);
909 cons.D1(sol(3),ptrst,d1);
911 temp.SetXYZ(pts.XYZ()- ptgui.XYZ());
912 secmember(1) = normtg - dnplan.Dot(temp);
914 temp.SetXYZ(ptrst.XYZ()- ptgui.XYZ());
915 secmember(2) = normtg - dnplan.Dot(temp);
917 ns = d1u1.Crossed(d1v1);
918 ncrossns = nplan.Crossed(ns);
919 ndotns = nplan.Dot(ns);
920 norm = ncrossns.Magnitude();
922 norm = 1; // Not enough, but it is not necessary to stop
924 cout << " SurfRstConstRad : Singular Surface " << endl;
928 // Derivative of n1 corresponding to w
930 grosterme = ncrossns.Dot(dnplan.Crossed(ns))/norm/norm;
931 dnw.SetLinearForm((dnplan.Dot(ns)-grosterme*ndotns)/norm,nplan,
935 temp.SetLinearForm(ndotns/norm,nplan, -1./norm,ns);
936 resul.SetLinearForm(ray,temp,gp_Vec(ptrst,pts));
937 secmember(3) = dnw.Dot(resul);
938 secmember(3) = -2.*ray*secmember(3);
940 math_Gauss Resol(gradsol, 1.e-9);
943 if (Resol.IsDone()) {
944 istgt = Standard_False;
945 Resol.Solve(secmember);
948 math_SVD SingRS (gradsol);
949 if (SingRS.IsDone()) {
950 math_Vector DEDT(1,3);
952 SingRS.Solve(DEDT, secmember, 1.e-6);
953 istgt = Standard_False;
955 else istgt = Standard_True;
959 tgs.SetLinearForm(secmember(1),d1u1,secmember(2),d1v1);
960 tgrst = secmember(3)*d1;
962 // Derivative of n1 corresponding to u1
963 temp = d2u1.Crossed(d1v1).Added(d1u1.Crossed(d2uv1));
964 grosterme = ncrossns.Dot(nplan.Crossed(temp))/norm/norm;
965 resulu.SetLinearForm(-(grosterme*ndotns-nplan.Dot(temp))/norm,nplan,
969 // Derivative of n1 corresponding to v1
970 temp = d2uv1.Crossed(d1v1).Added(d1u1.Crossed(d2v1));
971 grosterme = ncrossns.Dot(nplan.Crossed(temp))/norm/norm;
972 resulv.SetLinearForm(-(grosterme*ndotns-nplan.Dot(temp))/norm,nplan,
977 dnw.SetLinearForm(secmember(1),resulu,secmember(2),resulv,dnw);
978 ns.SetLinearForm(ndotns/norm,nplan, -1./norm,ns);
980 dn2w.SetLinearForm(ray, dnw, -1., tgrst, tgs);
981 norm = resul.Magnitude();
983 ns2 = -resul.Normalized();
984 dn2w.SetLinearForm(ns2.Dot(dn2w),ns2,-1.,dn2w);
987 ns.SetLinearForm(ndotns/norm,nplan, -1./norm,ns);
988 ns2 = -resul.Normalized();
993 Poles2d(Poles2d.Lower()).SetCoord(sol(1),sol(2));
994 Poles2d(Poles2d.Upper()).SetCoord(pt2drst.X(),pt2drst.Y());
996 DPoles2d(Poles2d.Lower()).SetCoord(secmember(1),secmember(2));
997 surfrst->D1(pt2drst.X(),pt2drst.Y(),bid,d1urst,d1vrst);
999 t3dto2d(a,b,tgrst,d1urst,d1vrst);
1000 DPoles2d(Poles2d.Upper()).SetCoord(a,b);
1004 if (mySShape == BlendFunc_Linear) {
1011 DPoles(upp) = tgrst;
1012 DWeights(low) = 0.0;
1013 DWeights(upp) = 0.0;
1018 // Case of the circle
1019 Center.SetXYZ(pts.XYZ()+ray*ns.XYZ());
1021 tgct = tgs.Added(ray*dnw);
1035 return GeomFill::GetCircle(myTConv,
1049 GeomFill::GetCircle(myTConv,
1054 return Standard_False;
1058 //=======================================================================
1059 //function : Section
1061 //=======================================================================
1063 Standard_Boolean BRepBlend_SurfRstConstRad::Section
1064 (const Blend_Point&,
1065 TColgp_Array1OfPnt&,
1066 TColgp_Array1OfVec&,
1067 TColgp_Array1OfVec&,
1068 TColgp_Array1OfPnt2d&,
1069 TColgp_Array1OfVec2d&,
1070 TColgp_Array1OfVec2d&,
1071 TColStd_Array1OfReal&,
1072 TColStd_Array1OfReal&,
1073 TColStd_Array1OfReal&)
1075 return Standard_False;
1078 void BRepBlend_SurfRstConstRad::Resolution(const Standard_Integer IC2d,
1079 const Standard_Real Tol,
1080 Standard_Real& TolU,
1081 Standard_Real& TolV) const
1084 TolU = surf->UResolution(Tol);
1085 TolV = surf->VResolution(Tol);
1088 TolU = surfrst->UResolution(Tol);
1089 TolV = surfrst->VResolution(Tol);