1d54b807 |
1 | // Created by: Julia GERASIMOVA |
2 | // Copyright (c) 2015 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
15 | #include <Adaptor3d_HCurve.hxx> |
16 | #include <Adaptor3d_HSurface.hxx> |
17 | #include <Blend_Point.hxx> |
18 | #include <BlendFunc.hxx> |
19 | #include <BlendFunc_ConstThroatWithPenetration.hxx> |
20 | #include <ElCLib.hxx> |
21 | #include <gp_Lin.hxx> |
22 | #include <gp_Pnt.hxx> |
23 | #include <gp_Vec.hxx> |
24 | #include <gp_Vec2d.hxx> |
25 | #include <math_Matrix.hxx> |
26 | #include <math_Gauss.hxx> |
27 | #include <Precision.hxx> |
28 | #include <Standard_NotImplemented.hxx> |
29 | |
30 | #define Eps 1.e-15 |
31 | |
32 | |
33 | //======================================================================= |
34 | //function : BlendFunc_ConstThroatWithPenetration |
35 | //purpose : |
36 | //======================================================================= |
37 | |
38 | BlendFunc_ConstThroatWithPenetration:: |
39 | BlendFunc_ConstThroatWithPenetration(const Handle(Adaptor3d_HSurface)& S1, |
40 | const Handle(Adaptor3d_HSurface)& S2, |
41 | const Handle(Adaptor3d_HCurve)& C) |
42 | : BlendFunc_ConstThroat(S1,S2,C) |
43 | { |
44 | } |
45 | |
46 | //======================================================================= |
47 | //function : IsSolution |
48 | //purpose : |
49 | //======================================================================= |
50 | |
51 | Standard_Boolean BlendFunc_ConstThroatWithPenetration:: |
52 | IsSolution(const math_Vector& Sol, const Standard_Real Tol) |
53 | { |
54 | math_Vector secmember(1,4), valsol(1,4); |
55 | math_Matrix gradsol(1,4,1,4); |
56 | |
57 | Value(Sol, valsol); |
58 | Derivatives(Sol, gradsol); |
59 | |
60 | tol = Tol; |
61 | |
62 | gp_Vec dnplan, temp1, temp2, temp3; |
63 | |
64 | if (Abs(valsol(1)) <= Tol && |
65 | Abs(valsol(2)) <= Tol && |
66 | Abs(valsol(3)) <= Tol*Tol && |
67 | Abs(valsol(4)) <= Tol) |
68 | { |
69 | dnplan.SetLinearForm(1./normtg,d2gui, |
70 | -1./normtg*(nplan.Dot(d2gui)),nplan); |
71 | |
72 | temp1.SetXYZ(pts1.XYZ() - ptgui.XYZ()); |
73 | temp2.SetXYZ(pts2.XYZ() - ptgui.XYZ()); |
74 | temp3.SetXYZ(pts2.XYZ() - pts1.XYZ()); |
75 | surf1->D1(Sol(1),Sol(2),pts1,d1u1,d1v1); |
76 | surf2->D1(Sol(3),Sol(4),pts2,d1u2,d1v2); |
77 | |
78 | secmember(1) = nplan.Dot(d1gui) - dnplan.Dot(temp1); |
79 | secmember(2) = nplan.Dot(d1gui) - dnplan.Dot(temp2); |
80 | secmember(3) = 2.*d1gui.Dot(temp1); |
81 | secmember(4) = d1gui.Dot(temp3); |
82 | |
83 | math_Gauss Resol(gradsol); |
84 | if (Resol.IsDone()) { |
85 | Resol.Solve(secmember); |
86 | tg1.SetLinearForm(secmember(1),d1u1,secmember(2),d1v1); |
87 | tg2.SetLinearForm(secmember(3),d1u2,secmember(4),d1v2); |
88 | tg12d.SetCoord(secmember(1),secmember(2)); |
89 | tg22d.SetCoord(secmember(3),secmember(4)); |
90 | istangent = Standard_False; |
91 | } |
92 | else { |
93 | istangent = Standard_True; |
94 | } |
95 | |
96 | distmin = Min(distmin, pts1.Distance(pts2)); |
97 | |
98 | return Standard_True; |
99 | } |
100 | |
101 | return Standard_False; |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : Value |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | Standard_Boolean BlendFunc_ConstThroatWithPenetration::Value(const math_Vector& X, |
110 | math_Vector& F) |
111 | { |
112 | surf1->D0( X(1), X(2), pts1 ); |
113 | surf2->D0( X(3), X(4), pts2 ); |
114 | |
115 | F(1) = nplan.XYZ().Dot(pts1.XYZ()) + theD; |
116 | F(2) = nplan.XYZ().Dot(pts2.XYZ()) + theD; |
117 | |
118 | const gp_Vec vref(ptgui, pts1); |
119 | |
120 | F(3) = vref.SquareMagnitude() - Throat*Throat; |
121 | |
122 | const gp_Vec vec12(pts1, pts2); |
123 | |
124 | F(4) = vref.Dot(vec12); |
125 | |
126 | return Standard_True; |
127 | } |
128 | |
129 | //======================================================================= |
130 | //function : Derivatives |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | Standard_Boolean BlendFunc_ConstThroatWithPenetration::Derivatives(const math_Vector& X, |
135 | math_Matrix& D) |
136 | { |
137 | surf1->D1( X(1), X(2), pts1, d1u1, d1v1); |
138 | surf2->D1( X(3), X(4), pts2, d1u2, d1v2); |
139 | |
140 | D(1,1) = nplan.Dot(d1u1); |
141 | D(1,2) = nplan.Dot(d1v1); |
142 | D(1,3) = 0.; |
143 | D(1,4) = 0.; |
144 | D(2,1) = 0.; |
145 | D(2,2) = 0.; |
146 | D(2,3) = nplan.Dot(d1u2); |
147 | D(2,4) = nplan.Dot(d1v2); |
148 | D(3,1) = 2.*gp_Vec(ptgui,pts1).Dot(d1u1); |
149 | D(3,2) = 2.*gp_Vec(ptgui,pts1).Dot(d1v1); |
150 | D(3,3) = 0.; |
151 | D(3,4) = 0.; |
152 | D(4,1) = d1u1.Dot(gp_Vec(pts1,pts2)) - gp_Vec(ptgui,pts1).Dot(d1u1); |
153 | D(4,2) = d1v1.Dot(gp_Vec(pts1,pts2)) - gp_Vec(ptgui,pts1).Dot(d1v1); |
154 | D(4,3) = gp_Vec(ptgui,pts1).Dot(d1u2); |
155 | D(4,4) = gp_Vec(ptgui,pts1).Dot(d1v2); |
156 | |
157 | return Standard_True; |
158 | } |
159 | |
160 | //======================================================================= |
161 | //function : TangentOnS1 |
162 | //purpose : |
163 | //======================================================================= |
164 | |
165 | const gp_Vec& BlendFunc_ConstThroatWithPenetration::TangentOnS1 () const |
166 | { |
167 | if (istangent) |
168 | throw Standard_DomainError("BlendFunc_ConstThroatWithPenetration::TangentOnS1"); |
169 | return tg1; |
170 | } |
171 | |
172 | |
173 | //======================================================================= |
174 | //function : TangentOnS2 |
175 | //purpose : |
176 | //======================================================================= |
177 | |
178 | const gp_Vec& BlendFunc_ConstThroatWithPenetration::TangentOnS2 () const |
179 | { |
180 | if (istangent) |
181 | throw Standard_DomainError("BlendFunc_ConstThroatWithPenetration::TangentOnS2"); |
182 | return tg2; |
183 | } |
184 | |
185 | |
186 | //======================================================================= |
187 | //function : Tangent2dOnS1 |
188 | //purpose : |
189 | //======================================================================= |
190 | |
191 | const gp_Vec2d& BlendFunc_ConstThroatWithPenetration::Tangent2dOnS1 () const |
192 | { |
193 | if (istangent) |
194 | throw Standard_DomainError("BlendFunc_ConstThroatWithPenetration::Tangent2dOnS1"); |
195 | return tg12d; |
196 | } |
197 | |
198 | //======================================================================= |
199 | //function : Tangent2dOnS2 |
200 | //purpose : |
201 | //======================================================================= |
202 | |
203 | const gp_Vec2d& BlendFunc_ConstThroatWithPenetration::Tangent2dOnS2 () const |
204 | { |
205 | if (istangent) |
206 | throw Standard_DomainError("BlendFunc_ConstThroatWithPenetration::Tangent2dOnS2"); |
207 | return tg22d; |
208 | } |
209 | |
210 | //======================================================================= |
211 | //function : GetSectionSize |
212 | //purpose : |
213 | //======================================================================= |
214 | Standard_Real BlendFunc_ConstThroatWithPenetration::GetSectionSize() const |
215 | { |
216 | throw Standard_NotImplemented("BlendFunc_ConstThroatWithPenetration::GetSectionSize()"); |
217 | } |