b311480e |
1 | // Created on: 1997-02-12 |
2 | // Created by: Laurent BOURESCHE |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
42cf5bc1 |
18 | #include <BRepBlend_SurfPointConstRadInv.hxx> |
19 | #include <gp_Pnt.hxx> |
20 | #include <math_Matrix.hxx> |
7fd59977 |
21 | |
22 | //======================================================================= |
23 | //function : BRepBlend_SurfPointConstRadInv |
24 | //purpose : |
25 | //======================================================================= |
7fd59977 |
26 | BRepBlend_SurfPointConstRadInv::BRepBlend_SurfPointConstRadInv |
c22b52d6 |
27 | (const Handle(Adaptor3d_Surface)& S, |
28 | const Handle(Adaptor3d_Curve)& C) |
d533dafb |
29 | : surf(S), |
30 | curv(C), |
31 | ray(0.0), |
32 | choix(0) |
7fd59977 |
33 | { |
34 | } |
35 | |
36 | //======================================================================= |
37 | //function : Set |
38 | //purpose : |
39 | //======================================================================= |
40 | |
41 | void BRepBlend_SurfPointConstRadInv::Set(const Standard_Real R, |
42 | const Standard_Integer Choix) |
43 | { |
44 | choix = Choix; |
45 | switch (choix) { |
46 | case 1: |
47 | case 2: |
48 | { |
49 | ray = -Abs(R); |
50 | } |
51 | break; |
52 | case 3: |
53 | case 4: |
54 | { |
55 | ray = Abs(R); |
56 | } |
57 | break; |
58 | default: |
59 | { |
60 | ray = -Abs(R); |
61 | } |
62 | } |
63 | } |
64 | |
65 | //======================================================================= |
66 | //function : NbEquations |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | Standard_Integer BRepBlend_SurfPointConstRadInv::NbEquations() const |
71 | { |
72 | return 3; |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : Value |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | Standard_Boolean BRepBlend_SurfPointConstRadInv::Value(const math_Vector& X, |
81 | math_Vector& F) |
82 | { |
83 | Standard_Real theD,norm,unsurnorm; |
84 | gp_Pnt ptcur,pts; |
85 | gp_Vec d1cur(0.,0.,0.),d1u(0.,0.,0.),d1v(0.,0.,0.); |
86 | gp_XYZ nplan(0.,0.,0.),ns(0.,0.,0.),ref(0.,0.,0.); |
87 | curv->D1(X(1),ptcur,d1cur); |
88 | nplan = d1cur.Normalized().XYZ(); |
89 | // theD = -(nplan.Dot(ptcur.XYZ())); |
90 | gp_XYZ ptcurXYZ(ptcur.XYZ()); |
91 | theD = nplan.Dot(ptcurXYZ) ; |
92 | theD = theD * (-1.) ; |
93 | |
94 | surf->D1(X(2),X(3),pts,d1u,d1v); |
95 | F(1) = nplan.Dot(point.XYZ()) + theD; |
96 | F(2) = nplan.Dot(pts.XYZ()) + theD; |
97 | ns = d1u.Crossed(d1v).XYZ(); |
98 | norm = nplan.Crossed(ns).Modulus(); |
99 | unsurnorm = 1./norm; |
100 | ns.SetLinearForm(nplan.Dot(ns),nplan, -1.,ns); |
101 | ns.Multiply(unsurnorm); |
102 | ref = pts.XYZ() - point.XYZ(); |
103 | ref.SetLinearForm(ray,ns,ref); |
104 | F(3) = ref.SquareModulus() - ray*ray; |
105 | return Standard_True; |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : Derivatives |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | Standard_Boolean BRepBlend_SurfPointConstRadInv::Derivatives(const math_Vector& X, |
114 | math_Matrix& D) |
115 | { |
116 | gp_Pnt ptcur,pts; |
117 | gp_Vec d1cur,d2cur,nplan,dnplan,d1u,d1v,d2u,d2v,duv; |
118 | Standard_Real theD, dtheD, normd1cur, unsurnormd1cur; |
119 | |
120 | curv->D2(X(1),ptcur,d1cur,d2cur); |
121 | normd1cur = d1cur.Magnitude(); |
122 | unsurnormd1cur = 1./normd1cur; |
123 | nplan = unsurnormd1cur * d1cur; |
124 | // theD = -(nplan.XYZ().Dot(ptcur.XYZ())); |
125 | gp_XYZ nplanXYZ(nplan.XYZ()); |
126 | gp_XYZ ptcurXYZ(ptcur.XYZ()); |
127 | theD = nplanXYZ.Dot(ptcurXYZ) ; |
128 | theD = theD * (-1.) ; |
129 | |
130 | dnplan.SetLinearForm(-nplan.Dot(d2cur),nplan,d2cur); |
131 | dnplan.Multiply(unsurnormd1cur); |
132 | dtheD = - nplan.XYZ().Dot(d1cur.XYZ()) - dnplan.XYZ().Dot(ptcur.XYZ()); |
133 | D(1,1) = dnplan.XYZ().Dot(point.XYZ()) + dtheD; |
134 | D(1,2) = D(1,3) = 0.; |
135 | surf->D2(X(2),X(3),pts,d1u,d1v,d2u,d2v,duv); |
136 | D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD; |
137 | D(2,2) = nplan.Dot(d1u); |
138 | D(2,3) = nplan.Dot(d1v); |
139 | |
140 | gp_Vec nsurf = d1u.Crossed(d1v); |
141 | gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv)); |
142 | gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v)); |
143 | |
144 | gp_Vec nplancrosnsurf = nplan.Crossed(nsurf); |
145 | gp_Vec dwnplancrosnsurf = dnplan.Crossed(nsurf); |
146 | gp_Vec dunplancrosnsurf = nplan.Crossed(dunsurf); |
147 | gp_Vec dvnplancrosnsurf = nplan.Crossed(dvnsurf); |
148 | |
149 | Standard_Real norm2 = nplancrosnsurf.SquareMagnitude(); |
150 | Standard_Real norm = sqrt(norm2); |
151 | Standard_Real unsurnorm = 1./norm; |
152 | Standard_Real raysurnorm = ray*unsurnorm; |
153 | Standard_Real unsurnorm2 = unsurnorm * unsurnorm; |
154 | Standard_Real raysurnorm2 = ray*unsurnorm2; |
155 | Standard_Real dwnorm = unsurnorm*nplancrosnsurf.Dot(dwnplancrosnsurf); |
156 | Standard_Real dunorm = unsurnorm*nplancrosnsurf.Dot(dunplancrosnsurf); |
157 | Standard_Real dvnorm = unsurnorm*nplancrosnsurf.Dot(dvnplancrosnsurf); |
158 | |
159 | Standard_Real nplandotnsurf = nplan.Dot(nsurf); |
160 | Standard_Real dwnplandotnsurf = dnplan.Dot(nsurf); |
161 | Standard_Real dunplandotnsurf = nplan.Dot(dunsurf); |
162 | Standard_Real dvnplandotnsurf = nplan.Dot(dvnsurf); |
163 | |
164 | gp_Vec temp,dwtemp,dutemp,dvtemp; |
165 | temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf); |
166 | dwtemp.SetLinearForm(nplandotnsurf,dnplan,dwnplandotnsurf,nplan); |
167 | dutemp.SetLinearForm(dunplandotnsurf,nplan,-1.,dunsurf); |
168 | dvtemp.SetLinearForm(dvnplandotnsurf,nplan,-1.,dvnsurf); |
169 | |
170 | gp_Vec ref,dwref,duref,dvref,corde(point,pts); |
171 | ref.SetLinearForm(raysurnorm,temp,corde); |
172 | dwref.SetLinearForm(raysurnorm,dwtemp,-raysurnorm2*dwnorm,temp); |
173 | duref.SetLinearForm(raysurnorm,dutemp,-raysurnorm2*dunorm,temp,d1u); |
174 | dvref.SetLinearForm(raysurnorm,dvtemp,-raysurnorm2*dvnorm,temp,d1v); |
175 | |
176 | ref.Add(ref); |
177 | D(3,1) = ref.Dot(dwref); |
178 | D(3,2) = ref.Dot(duref); |
179 | D(3,3) = ref.Dot(dvref); |
180 | |
181 | return Standard_True; |
182 | } |
183 | |
184 | //======================================================================= |
185 | //function : Values |
186 | //purpose : |
187 | //======================================================================= |
188 | |
189 | Standard_Boolean BRepBlend_SurfPointConstRadInv::Values(const math_Vector& X, |
190 | math_Vector& F, |
191 | math_Matrix& D) |
192 | { |
193 | gp_Pnt ptcur,pts; |
194 | gp_Vec d1cur,d2cur,nplan,dnplan,d1u,d1v,d2u,d2v,duv; |
195 | Standard_Real theD, dtheD, normd1cur, unsurnormd1cur; |
196 | |
197 | curv->D2(X(1),ptcur,d1cur,d2cur); |
198 | surf->D2(X(2),X(3),pts,d1u,d1v,d2u,d2v,duv); |
199 | normd1cur = d1cur.Magnitude(); |
200 | unsurnormd1cur = 1./normd1cur; |
201 | nplan = unsurnormd1cur * d1cur; |
202 | // theD = -(nplan.XYZ().Dot(ptcur.XYZ())); |
203 | gp_XYZ nplanXYZ(nplan.XYZ()); |
204 | gp_XYZ ptcurXYZ(ptcur.XYZ()); |
205 | theD = nplanXYZ.Dot(ptcurXYZ) ; |
206 | theD = theD * (-1.) ; |
207 | |
208 | F(1) = nplan.XYZ().Dot(point.XYZ()) + theD; |
209 | F(2) = nplan.XYZ().Dot(pts.XYZ()) + theD; |
210 | |
211 | dnplan.SetLinearForm(-nplan.Dot(d2cur),nplan,d2cur); |
212 | dnplan.Multiply(unsurnormd1cur); |
213 | dtheD = - nplan.XYZ().Dot(d1cur.XYZ()) - dnplan.XYZ().Dot(ptcur.XYZ()); |
214 | D(1,1) = dnplan.XYZ().Dot(point.XYZ()) + dtheD; |
215 | D(1,2) = D(1,3) = 0.; |
216 | D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD; |
217 | D(2,2) = nplan.Dot(d1u); |
218 | D(2,3) = nplan.Dot(d1v); |
219 | |
220 | gp_Vec nsurf = d1u.Crossed(d1v); |
221 | gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv)); |
222 | gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v)); |
223 | |
224 | gp_Vec nplancrosnsurf = nplan.Crossed(nsurf); |
225 | gp_Vec dwnplancrosnsurf = dnplan.Crossed(nsurf); |
226 | gp_Vec dunplancrosnsurf = nplan.Crossed(dunsurf); |
227 | gp_Vec dvnplancrosnsurf = nplan.Crossed(dvnsurf); |
228 | |
229 | Standard_Real norm2 = nplancrosnsurf.SquareMagnitude(); |
230 | Standard_Real norm = sqrt(norm2); |
231 | Standard_Real unsurnorm = 1./norm; |
232 | Standard_Real raysurnorm = ray*unsurnorm; |
233 | Standard_Real unsurnorm2 = unsurnorm * unsurnorm; |
234 | Standard_Real raysurnorm2 = ray*unsurnorm2; |
235 | Standard_Real dwnorm = unsurnorm*nplancrosnsurf.Dot(dwnplancrosnsurf); |
236 | Standard_Real dunorm = unsurnorm*nplancrosnsurf.Dot(dunplancrosnsurf); |
237 | Standard_Real dvnorm = unsurnorm*nplancrosnsurf.Dot(dvnplancrosnsurf); |
238 | |
239 | Standard_Real nplandotnsurf = nplan.Dot(nsurf); |
240 | Standard_Real dwnplandotnsurf = dnplan.Dot(nsurf); |
241 | Standard_Real dunplandotnsurf = nplan.Dot(dunsurf); |
242 | Standard_Real dvnplandotnsurf = nplan.Dot(dvnsurf); |
243 | |
244 | gp_Vec temp,dwtemp,dutemp,dvtemp; |
245 | temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf); |
246 | dwtemp.SetLinearForm(nplandotnsurf,dnplan,dwnplandotnsurf,nplan); |
247 | dutemp.SetLinearForm(dunplandotnsurf,nplan,-1.,dunsurf); |
248 | dvtemp.SetLinearForm(dvnplandotnsurf,nplan,-1.,dvnsurf); |
249 | |
250 | gp_Vec ref,dwref,duref,dvref,corde(point,pts); |
251 | ref.SetLinearForm(raysurnorm,temp,corde); |
252 | F(3) = ref.SquareMagnitude() - ray*ray; |
253 | dwref.SetLinearForm(raysurnorm,dwtemp,-raysurnorm2*dwnorm,temp); |
254 | duref.SetLinearForm(raysurnorm,dutemp,-raysurnorm2*dunorm,temp,d1u); |
255 | dvref.SetLinearForm(raysurnorm,dvtemp,-raysurnorm2*dvnorm,temp,d1v); |
256 | |
257 | ref.Add(ref); |
258 | D(3,1) = ref.Dot(dwref); |
259 | D(3,2) = ref.Dot(duref); |
260 | D(3,3) = ref.Dot(dvref); |
261 | |
262 | return Standard_True; |
263 | } |
264 | |
265 | //======================================================================= |
266 | //function : Set |
267 | //purpose : |
268 | //======================================================================= |
269 | |
270 | void BRepBlend_SurfPointConstRadInv::Set(const gp_Pnt& P) |
271 | { |
272 | point = P; |
273 | } |
274 | |
275 | //======================================================================= |
276 | //function : GetTolerance |
277 | //purpose : |
278 | //======================================================================= |
279 | |
280 | void BRepBlend_SurfPointConstRadInv::GetTolerance(math_Vector& Tolerance, |
281 | const Standard_Real Tol) const |
282 | { |
283 | Tolerance(1) = curv->Resolution(Tol); |
284 | Tolerance(2) = surf->UResolution(Tol); |
285 | Tolerance(3) = surf->VResolution(Tol); |
286 | } |
287 | |
288 | //======================================================================= |
289 | //function : GetBounds |
290 | //purpose : |
291 | //======================================================================= |
292 | |
293 | void BRepBlend_SurfPointConstRadInv::GetBounds(math_Vector& InfBound, |
294 | math_Vector& SupBound) const |
295 | { |
296 | InfBound(1) = curv->FirstParameter(); |
297 | SupBound(1) = curv->LastParameter(); |
298 | InfBound(2) = surf->FirstUParameter(); |
299 | SupBound(2) = surf->LastUParameter(); |
300 | InfBound(3) = surf->FirstVParameter(); |
301 | SupBound(3) = surf->LastVParameter(); |
302 | } |
303 | |
304 | //======================================================================= |
305 | //function : IsSolution |
306 | //purpose : |
307 | //======================================================================= |
308 | |
309 | Standard_Boolean BRepBlend_SurfPointConstRadInv::IsSolution(const math_Vector& Sol, |
310 | const Standard_Real Tol) |
311 | { |
312 | math_Vector valsol(1,3); |
313 | Value(Sol,valsol); |
314 | if (Abs(valsol(1)) <= Tol && |
315 | Abs(valsol(2)) <= Tol && |
316 | Abs(valsol(3)) <= 2*Tol*Abs(ray) ) { |
317 | return Standard_True; |
318 | } |
319 | return Standard_False; |
320 | } |
321 | |
322 | |