Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1994-03-10 |
2 | // Created by: Yves FRICAUD | |
3 | // Copyright (c) 1994-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 | |
17 | #include <Bisector_BisecCC.ixx> | |
18 | #include <Bisector_BisecPC.hxx> | |
19 | #include <Bisector.hxx> | |
20 | #include <Bisector_Curve.hxx> | |
21 | #include <Bisector_FunctionH.hxx> | |
22 | #include <Bisector_PointOnBis.hxx> | |
23 | #include <Geom2dAdaptor_Curve.hxx> | |
24 | #include <Geom2d_Curve.hxx> | |
25 | #include <Geom2dLProp_CLProps2d.hxx> | |
26 | #include <Geom2dGcc.hxx> | |
27 | #include <Geom2dGcc_Circ2d2TanRad.hxx> | |
28 | #include <Geom2dGcc_QualifiedCurve.hxx> | |
29 | #include <Geom2d_TrimmedCurve.hxx> | |
30 | #include <Geom2d_Circle.hxx> | |
31 | #include <Geom2d_Line.hxx> | |
32 | #include <Geom2dInt_GInter.hxx> | |
33 | #include <Geom2dAPI_ProjectPointOnCurve.hxx> | |
34 | #include <gp_Pnt2d.hxx> | |
35 | #include <gp_Vec2d.hxx> | |
36 | #include <gp.hxx> | |
37 | #include <IntRes2d_IntersectionPoint.hxx> | |
38 | #include <Precision.hxx> | |
39 | #include <math_FunctionRoot.hxx> | |
40 | #include <math_FunctionRoots.hxx> | |
41 | #include <math_BissecNewton.hxx> | |
42 | ||
43 | #include <Standard_OutOfRange.hxx> | |
44 | #include <Standard_DivideByZero.hxx> | |
45 | #include <Standard_NotImplemented.hxx> | |
46 | ||
47 | ||
91bb31f3 | 48 | static Standard_Boolean ProjOnCurve (const gp_Pnt2d& P, |
873c119f | 49 | const Handle(Geom2d_Curve)& C, |
50 | Standard_Real& theParam); | |
7fd59977 | 51 | |
52 | static Standard_Real Curvature (const Handle(Geom2d_Curve)& C, | |
873c119f | 53 | Standard_Real U, |
54 | Standard_Real Tol) ; | |
7fd59977 | 55 | |
56 | static Standard_Boolean TestExtension (const Handle(Geom2d_Curve)& C1, | |
873c119f | 57 | const Handle(Geom2d_Curve)& C2, |
58 | const Standard_Integer Start_End); | |
7fd59977 | 59 | |
60 | static Standard_Boolean DiscretPar(const Standard_Real DU, | |
873c119f | 61 | const Standard_Real EpsMin, |
62 | const Standard_Real EpsMax, | |
63 | const Standard_Integer NbMin, | |
64 | const Standard_Integer NbMax, | |
65 | Standard_Real& Eps, | |
66 | Standard_Integer& Nb); | |
7fd59977 | 67 | |
68 | //============================================================================= | |
69 | //function : | |
70 | //purpose : | |
71 | //============================================================================= | |
72 | Bisector_BisecCC::Bisector_BisecCC() | |
73 | { | |
74 | shiftParameter = 0; | |
75 | isEmpty = Standard_False; | |
76 | } | |
77 | ||
78 | //============================================================================= | |
79 | //function : | |
80 | //purpose : | |
81 | //============================================================================= | |
82 | Bisector_BisecCC::Bisector_BisecCC(const Handle(Geom2d_Curve)& Cu1, | |
873c119f | 83 | const Handle(Geom2d_Curve)& Cu2, |
84 | const Standard_Real Side1, | |
85 | const Standard_Real Side2, | |
86 | const gp_Pnt2d& Origin, | |
87 | const Standard_Real DistMax) | |
7fd59977 | 88 | { |
89 | Perform (Cu1,Cu2,Side1,Side2,Origin,DistMax); | |
90 | } | |
91 | ||
92 | //============================================================================= | |
93 | //function : Perform | |
94 | //purpose : | |
95 | //============================================================================= | |
96 | void Bisector_BisecCC::Perform(const Handle(Geom2d_Curve)& Cu1, | |
873c119f | 97 | const Handle(Geom2d_Curve)& Cu2, |
98 | const Standard_Real Side1, | |
99 | const Standard_Real Side2, | |
100 | const gp_Pnt2d& Origin, | |
101 | const Standard_Real DistMax) | |
7fd59977 | 102 | { |
103 | isEmpty = Standard_False; | |
104 | distMax = DistMax; | |
105 | ||
106 | curve1 = Handle (Geom2d_Curve)::DownCast(Cu1->Copy()); | |
107 | curve2 = Handle (Geom2d_Curve)::DownCast(Cu2->Copy()); | |
108 | ||
109 | sign1 = Side1; | |
110 | sign2 = Side2; | |
111 | ||
112 | isConvex1 = Bisector::IsConvex(curve1,sign1); | |
113 | isConvex2 = Bisector::IsConvex(curve2,sign2); | |
114 | ||
115 | Standard_Real U,UC1,UC2,Dist,dU,USol; | |
116 | gp_Pnt2d P; | |
117 | Standard_Integer NbPnts = 21; | |
118 | Standard_Real EpsMin = 10*Precision::Confusion(); | |
119 | Standard_Boolean YaPoly = Standard_True; | |
120 | Standard_Boolean OriInPoly = Standard_False; | |
121 | //--------------------------------------------- | |
0d969553 | 122 | // Calculate first point of the polygon. |
7fd59977 | 123 | //--------------------------------------------- |
91bb31f3 | 124 | Standard_Boolean isProjDone = ProjOnCurve (Origin,curve1, U); |
91bb31f3 | 125 | |
126 | if(!isProjDone) | |
127 | { | |
128 | isEmpty = Standard_True; | |
129 | return; | |
130 | } | |
7fd59977 | 131 | |
873c119f | 132 | P = ValueByInt (U,UC1,UC2,Dist); |
133 | if(Dist < Precision::Confusion()) | |
134 | { | |
135 | gp_Pnt2d aP1 = curve1->Value(UC1); | |
136 | gp_Pnt2d aP2 = curve2->Value(UC2); | |
137 | Standard_Real dp = (aP1.Distance(P)+aP2.Distance(P)); | |
138 | Standard_Real dorig = (aP1.Distance(Origin)+aP2.Distance(Origin)); | |
139 | if(dp < dorig) | |
140 | { | |
141 | isEmpty = Standard_True; | |
142 | return; | |
143 | } | |
144 | } | |
145 | ||
7fd59977 | 146 | if (Dist < Precision::Infinite()) { |
147 | //---------------------------------------------------- | |
0d969553 Y |
148 | // the parameter of the origin point gives a point |
149 | // on the polygon. | |
7fd59977 | 150 | //---------------------------------------------------- |
151 | myPolygon.Append(Bisector_PointOnBis(UC1,UC2,U,Dist,P)); | |
152 | startIntervals.Append(U); | |
153 | if (P.IsEqual(Origin,Precision::Confusion())) { | |
154 | //---------------------------------------- | |
0d969553 | 155 | // test if the first point is the origin. |
7fd59977 | 156 | //---------------------------------------- |
157 | OriInPoly = Standard_True; | |
158 | } | |
159 | } | |
160 | else { | |
161 | //------------------------------------------------------- | |
0d969553 Y |
162 | // The origin point is on the extension. |
163 | // Find the first point of the polygon by dichotomy. | |
7fd59977 | 164 | //------------------------------------------------------- |
165 | dU = (curve1->LastParameter() - U)/(NbPnts - 1); | |
166 | U += dU; | |
167 | for (Standard_Integer i = 1; i <= NbPnts - 1; i++) { | |
168 | P = ValueByInt(U,UC1,UC2,Dist); | |
169 | if (Dist < Precision::Infinite()) { | |
91bb31f3 | 170 | USol = SearchBound(U - dU,U); |
171 | P = ValueByInt(USol,UC1,UC2,Dist); | |
172 | startIntervals.Append(USol); | |
173 | myPolygon.Append(Bisector_PointOnBis(UC1,UC2,USol,Dist,P)); | |
174 | break; | |
7fd59977 | 175 | } |
176 | U += dU; | |
177 | } | |
178 | } | |
179 | ||
c29a9290 | 180 | if ( myPolygon.Length() != 0 ) { |
7fd59977 | 181 | SupLastParameter(); |
182 | //---------------------------------------------- | |
0d969553 | 183 | // Construction of the polygon of the bissectrice. |
7fd59977 | 184 | //--------------------------------------------- |
185 | U = FirstParameter(); | |
186 | Standard_Real DU = LastParameter() - U; | |
187 | ||
188 | if (DU < EpsMin) {NbPnts = 3;} | |
189 | dU = DU/(NbPnts - 1); | |
190 | ||
191 | U += dU; | |
91bb31f3 | 192 | // modified by NIZHNY-EAP Fri Jan 21 09:33:20 2000 ___BEGIN___ |
193 | // prevent addition of the same point | |
7fd59977 | 194 | gp_Pnt2d prevPnt = P; |
195 | for (Standard_Integer i = 1; i <= NbPnts - 1; i++) { | |
196 | P = ValueByInt(U,UC1,UC2,Dist); | |
197 | if (Dist < Precision::Infinite()) { | |
91bb31f3 | 198 | if (P.Distance (prevPnt) > Precision::Confusion()) |
199 | myPolygon.Append(Bisector_PointOnBis(UC1,UC2,U,Dist,P)); | |
7fd59977 | 200 | } |
201 | else { | |
91bb31f3 | 202 | USol = SearchBound(U - dU,U); |
203 | P = ValueByInt(USol,UC1,UC2,Dist); | |
204 | endIntervals.SetValue(1,USol); | |
205 | if (P.Distance (prevPnt) > Precision::Confusion()) | |
206 | myPolygon.Append(Bisector_PointOnBis(UC1,UC2,USol,Dist,P)); | |
207 | break; | |
7fd59977 | 208 | } |
209 | U += dU; | |
210 | prevPnt=P; | |
91bb31f3 | 211 | // modified by NIZHNY-EAP Fri Jan 21 09:33:24 2000 ___END___ |
7fd59977 | 212 | } |
213 | } | |
214 | else { | |
215 | //---------------- | |
0d969553 | 216 | // Empty Polygon. |
7fd59977 | 217 | //---------------- |
218 | YaPoly = Standard_False; | |
219 | } | |
91bb31f3 | 220 | |
7fd59977 | 221 | extensionStart = Standard_False; |
222 | extensionEnd = Standard_False; | |
223 | pointStart = Origin; | |
224 | ||
225 | if (isConvex1 && isConvex2) { | |
226 | if (YaPoly) pointEnd = myPolygon.Last().Point(); | |
227 | } | |
228 | else { | |
229 | //----------------------------------------------------------------------------- | |
0d969553 Y |
230 | // Extension : The curve is extended at the beginning and/or the end if |
231 | // - one of two curves is concave. | |
232 | // - the curves have a common point at the beginning and/or the end | |
233 | // - the angle of opening at the common point between two curves | |
c6541a0c | 234 | // values M_PI. |
0d969553 Y |
235 | // the extension at the beginning is taken into account if the origin is found above. |
236 | // ie : the origin is not the in the polygon. | |
7fd59977 | 237 | //----------------------------------------------------------------------------- |
91bb31f3 | 238 | |
7fd59977 | 239 | //--------------------------------- |
0d969553 | 240 | // Do the extensions exist ? |
7fd59977 | 241 | //--------------------------------- |
242 | if (OriInPoly) { | |
243 | extensionStart = Standard_False; | |
244 | } | |
245 | else { | |
246 | extensionStart = TestExtension(curve1,curve2,1); | |
247 | } | |
248 | extensionEnd = TestExtension(curve1,curve2,2); | |
249 | ||
250 | //----------------- | |
0d969553 | 251 | // Calculate pointEnd. |
7fd59977 | 252 | //----------------- |
253 | if (extensionEnd) { | |
254 | pointEnd = curve1->Value(curve1->LastParameter()); | |
255 | } | |
256 | else if (YaPoly) { | |
257 | pointEnd = myPolygon.Last().Point(); | |
258 | } | |
259 | else { | |
260 | ComputePointEnd(); | |
261 | } | |
262 | //------------------------------------------------------ | |
0d969553 | 263 | // Update the Limits of intervals of definition. |
7fd59977 | 264 | //------------------------------------------------------ |
265 | if (YaPoly) { | |
266 | if (extensionStart) { | |
91bb31f3 | 267 | gp_Pnt2d P1 = myPolygon.First().Point(); |
268 | Standard_Real UFirst = startIntervals.First() - pointStart.Distance(P1); | |
269 | startIntervals.InsertBefore(1,UFirst); | |
270 | endIntervals .InsertBefore(1,startIntervals.Value(2)); | |
7fd59977 | 271 | } |
272 | if (extensionEnd) { | |
91bb31f3 | 273 | gp_Pnt2d P1; |
274 | Standard_Real UFirst,ULast; | |
275 | P1 = myPolygon.Last().Point(); | |
276 | UFirst = endIntervals.Last(); | |
277 | ULast = UFirst + pointEnd.Distance(P1); | |
278 | startIntervals.Append(UFirst); | |
279 | endIntervals .Append(ULast ); | |
7fd59977 | 280 | } |
281 | } | |
282 | else { | |
283 | //-------------------------------------------------- | |
0d969553 | 284 | // No polygon => the bissectrice is a segment. |
7fd59977 | 285 | //-------------------------------------------------- |
286 | startIntervals.Append(0.); | |
287 | endIntervals .Append(pointEnd.Distance(pointStart)); | |
288 | } | |
289 | } | |
290 | if (!YaPoly && !extensionStart && !extensionEnd) | |
291 | isEmpty = Standard_True; | |
91bb31f3 | 292 | // modified by NIZHNY-EAP Mon Jan 17 17:32:40 2000 ___BEGIN___ |
7fd59977 | 293 | if (myPolygon.Length() <= 2) |
294 | isEmpty = Standard_True; | |
91bb31f3 | 295 | // modified by NIZHNY-EAP Mon Jan 17 17:32:42 2000 ___END___ |
7fd59977 | 296 | } |
297 | ||
298 | //============================================================================= | |
299 | //function : IsExtendAtStart | |
300 | //purpose : | |
301 | //============================================================================= | |
302 | Standard_Boolean Bisector_BisecCC::IsExtendAtStart() const | |
303 | { | |
304 | return extensionStart; | |
305 | } | |
306 | ||
307 | //============================================================================= | |
308 | //function : IsExtendAtEnd | |
309 | //purpose : | |
310 | //============================================================================= | |
311 | Standard_Boolean Bisector_BisecCC::IsExtendAtEnd() const | |
312 | { | |
313 | return extensionEnd; | |
314 | } | |
315 | ||
316 | //============================================================================= | |
317 | //function : IsEmpty | |
318 | //purpose : | |
319 | //============================================================================= | |
320 | Standard_Boolean Bisector_BisecCC::IsEmpty() const | |
321 | { | |
322 | return isEmpty; | |
323 | } | |
324 | ||
325 | //============================================================================= | |
326 | //function : Reverse | |
327 | //purpose : | |
328 | //============================================================================= | |
329 | void Bisector_BisecCC::Reverse() | |
330 | { | |
331 | Standard_NotImplemented::Raise(); | |
332 | } | |
333 | ||
334 | //============================================================================= | |
335 | //function : ReversedParameter | |
336 | // purpose : | |
337 | //============================================================================= | |
338 | Standard_Real Bisector_BisecCC::ReversedParameter(const Standard_Real U) const | |
339 | { | |
340 | return LastParameter() + FirstParameter() - U; | |
341 | } | |
342 | ||
343 | //============================================================================= | |
344 | //function : Copy | |
345 | //purpose : | |
346 | //============================================================================= | |
347 | Handle(Geom2d_Geometry) Bisector_BisecCC::Copy() const | |
348 | { | |
349 | Handle(Geom2d_Curve) CopyCurve1 | |
350 | = Handle(Geom2d_Curve)::DownCast(curve1->Copy()); | |
351 | Handle(Geom2d_Curve) CopyCurve2 | |
352 | = Handle(Geom2d_Curve)::DownCast(curve2->Copy()); | |
353 | ||
354 | Handle(Bisector_BisecCC) C = new Bisector_BisecCC(); | |
355 | ||
356 | C -> Curve (1, CopyCurve1) ; C -> Curve (2, CopyCurve2); | |
357 | C -> Sign (1, sign1 ) ; C -> Sign (2, sign2 ); | |
358 | C -> IsConvex (1, isConvex1) ; C -> IsConvex (2, isConvex2); | |
359 | C -> Polygon (myPolygon); | |
360 | C -> IsEmpty (isEmpty) ; | |
361 | C -> DistMax (distMax) ; | |
362 | C -> StartIntervals (startIntervals); C -> EndIntervals (endIntervals); | |
363 | C -> ExtensionStart (extensionStart); C -> ExtensionEnd (extensionEnd); | |
364 | C -> PointStart (pointStart) ; C -> PointEnd (pointEnd) ; | |
365 | ||
366 | return C; | |
367 | } | |
368 | ||
369 | //============================================================================= | |
370 | //function : ChangeGuide | |
0d969553 Y |
371 | //purpose : Changet of the guideline for the parameters of the bissectrice |
372 | // ATTENTION : - This can invert the direction of parameterization. | |
373 | // - This concerns only the part of the curve | |
374 | // corresponding to the polygon. | |
7fd59977 | 375 | //============================================================================= |
376 | Handle(Bisector_BisecCC) Bisector_BisecCC::ChangeGuide() const | |
377 | { | |
378 | Handle(Bisector_BisecCC) C = new Bisector_BisecCC(); | |
873c119f | 379 | |
7fd59977 | 380 | C -> Curve (1, curve2) ; C -> Curve (2, curve1); |
381 | C -> Sign (1, sign2 ) ; C -> Sign (2, sign1 ); | |
382 | C -> IsConvex (1, isConvex2); C -> IsConvex (2, isConvex1); | |
873c119f | 383 | |
7fd59977 | 384 | //------------------------------------------------------------------------- |
0d969553 Y |
385 | // Construction of the new polygon from the initial one. |
386 | // inversion of PointOnBis and Calculation of new parameters on the bissectrice. | |
7fd59977 | 387 | //------------------------------------------------------------------------- |
388 | Bisector_PolyBis Poly; | |
389 | if (sign1 == sign2 ) { | |
390 | //--------------------------------------------------------------- | |
0d969553 | 391 | // elements of the new polygon are ranked in the other direction. |
7fd59977 | 392 | //--------------------------------------------------------------- |
393 | for (Standard_Integer i = myPolygon.Length(); i >=1; i--) { | |
394 | Bisector_PointOnBis P = myPolygon.Value(i); | |
395 | Bisector_PointOnBis NewP (P.ParamOnC2(), P.ParamOnC1(), | |
873c119f | 396 | P.ParamOnC2(), P.Distance (), |
397 | P.Point()); | |
7fd59977 | 398 | Poly.Append (NewP); |
399 | } | |
400 | } | |
401 | else { | |
402 | for (Standard_Integer i = 1; i <= myPolygon.Length(); i ++) { | |
403 | Bisector_PointOnBis P = myPolygon.Value(i); | |
404 | Bisector_PointOnBis NewP (P.ParamOnC2(), P.ParamOnC1(), | |
873c119f | 405 | P.ParamOnC2(), P.Distance (), |
406 | P.Point()); | |
7fd59977 | 407 | Poly.Append (NewP); |
408 | } | |
409 | } | |
410 | C -> Polygon (Poly); | |
411 | C -> FirstParameter (Poly.First().ParamOnBis()); | |
412 | C -> LastParameter (Poly.Last() .ParamOnBis()); | |
873c119f | 413 | |
7fd59977 | 414 | return C; |
415 | } | |
416 | ||
417 | //============================================================================= | |
418 | //function : Transform | |
419 | //purpose : | |
420 | //============================================================================= | |
421 | void Bisector_BisecCC::Transform (const gp_Trsf2d& T) | |
422 | { | |
423 | curve1 ->Transform(T); | |
424 | curve2 ->Transform(T); | |
425 | myPolygon . Transform(T); | |
426 | pointStart. Transform(T); | |
427 | pointEnd . Transform(T); | |
428 | } | |
429 | ||
430 | //============================================================================= | |
431 | //function : IsCN | |
432 | //purpose : | |
433 | //============================================================================= | |
434 | Standard_Boolean Bisector_BisecCC::IsCN (const Standard_Integer N) const | |
435 | { | |
436 | return (curve1->IsCN(N+1) && curve2->IsCN(N+1)); | |
437 | } | |
438 | ||
439 | //============================================================================= | |
440 | //function : FirstParameter | |
441 | //purpose : | |
442 | //============================================================================= | |
443 | Standard_Real Bisector_BisecCC::FirstParameter() const | |
444 | { | |
873c119f | 445 | return startIntervals.First(); |
7fd59977 | 446 | } |
447 | ||
448 | //============================================================================= | |
449 | //function : LastParameter | |
450 | //purpose : | |
451 | //============================================================================= | |
452 | Standard_Real Bisector_BisecCC::LastParameter() const | |
453 | { | |
873c119f | 454 | return endIntervals.Last(); |
7fd59977 | 455 | } |
456 | ||
457 | //============================================================================= | |
458 | //function : Continuity | |
459 | //purpose : | |
460 | //============================================================================= | |
461 | GeomAbs_Shape Bisector_BisecCC::Continuity() const | |
462 | { | |
463 | GeomAbs_Shape Cont = curve1->Continuity(); | |
464 | switch (Cont) { | |
465 | case GeomAbs_C1 : return GeomAbs_C0; | |
466 | case GeomAbs_C2 : return GeomAbs_C1; | |
467 | case GeomAbs_C3 : return GeomAbs_C2; | |
468 | case GeomAbs_CN : return GeomAbs_CN; | |
7fd59977 | 469 | default: break; |
7fd59977 | 470 | } |
471 | return GeomAbs_C0; | |
472 | } | |
473 | ||
474 | //============================================================================= | |
475 | //function : NbIntervals | |
476 | //purpose : | |
477 | //============================================================================= | |
478 | Standard_Integer Bisector_BisecCC::NbIntervals() const | |
479 | { | |
480 | return startIntervals.Length(); | |
481 | } | |
482 | ||
483 | //============================================================================= | |
484 | //function : IntervalFirst | |
485 | //purpose : | |
486 | //============================================================================= | |
487 | Standard_Real Bisector_BisecCC::IntervalFirst(const Standard_Integer Index) const | |
488 | { | |
489 | return startIntervals.Value(Index); | |
490 | } | |
873c119f | 491 | |
7fd59977 | 492 | //============================================================================= |
493 | //function : IntervalLast | |
494 | //purpose : | |
495 | //============================================================================= | |
496 | Standard_Real Bisector_BisecCC::IntervalLast(const Standard_Integer Index) const | |
497 | { | |
498 | return endIntervals.Value(Index); | |
499 | } | |
500 | ||
501 | //============================================================================= | |
502 | //function : IntervalContinuity | |
503 | //purpose : | |
504 | //============================================================================= | |
505 | GeomAbs_Shape Bisector_BisecCC::IntervalContinuity() const | |
506 | { | |
507 | GeomAbs_Shape Cont = curve1->Continuity(); | |
508 | switch (Cont) { | |
509 | case GeomAbs_C1 : return GeomAbs_C0; | |
510 | case GeomAbs_C2 : return GeomAbs_C1; | |
511 | case GeomAbs_C3 : return GeomAbs_C2; | |
512 | case GeomAbs_CN : return GeomAbs_CN; | |
7fd59977 | 513 | default: break; |
7fd59977 | 514 | } |
515 | return GeomAbs_C0; | |
516 | } | |
517 | ||
518 | //============================================================================= | |
519 | //function : IsClosed | |
520 | //purpose : | |
521 | //============================================================================= | |
522 | Standard_Boolean Bisector_BisecCC::IsClosed() const | |
523 | { | |
524 | if (curve1->IsClosed()) { | |
525 | if (startIntervals.First() == curve1->FirstParameter() && | |
873c119f | 526 | endIntervals .Last () == curve1->LastParameter () ) |
7fd59977 | 527 | return Standard_True; |
528 | } | |
529 | return Standard_False; | |
530 | } | |
531 | ||
532 | //============================================================================= | |
533 | //function : IsPeriodic | |
534 | //purpose : | |
535 | //============================================================================= | |
536 | Standard_Boolean Bisector_BisecCC::IsPeriodic() const | |
537 | { | |
538 | return Standard_False; | |
539 | } | |
540 | ||
541 | ||
542 | //============================================================================= | |
543 | //function : Curvature | |
544 | //purpose : | |
545 | //============================================================================= | |
546 | static Standard_Real Curvature (const Handle(Geom2d_Curve)& C, | |
873c119f | 547 | Standard_Real U, |
548 | Standard_Real Tol) | |
7fd59977 | 549 | { |
550 | Standard_Real K1; | |
551 | gp_Vec2d D1,D2; | |
552 | gp_Pnt2d P; | |
553 | C->D2(U,P,D1,D2); | |
554 | Standard_Real Norm2 = D1.SquareMagnitude();; | |
555 | if (Norm2 < Tol) { | |
556 | K1 = 0.0; | |
557 | } | |
558 | else { | |
559 | K1 = (D1^D2)/(Norm2*sqrt(Norm2)); | |
560 | } | |
561 | return K1; | |
562 | } | |
563 | ||
564 | //============================================================================= | |
565 | //function : Value | |
0d969553 | 566 | //purpose : CALCULATE THE CURRENT POINT BY ITERATIVE METHOD. |
7fd59977 | 567 | // ---------------------------------------------- |
0d969553 Y |
568 | // Calculate the current point, the distance from the current point to |
569 | // both curves, the parameters on each curve of the projection | |
570 | // of the current point. | |
7fd59977 | 571 | // |
0d969553 Y |
572 | //method : - Find start parameter by using <myPolygon>. |
573 | // - Calculate parameter U2 on curve C2 solution of H(U,V)= 0 | |
7fd59977 | 574 | // - P(U) = F(U,U2) |
575 | // | |
0d969553 | 576 | // or : |
7fd59977 | 577 | // ||P2(v0)P1(u)||**2 |
578 | // F(u,v) = P1(u) - 1/2 *----------------* N(u) | |
579 | // (N(u).P2(v0)P1(u)) | |
580 | // | |
581 | // H(u,v) = (Tu.P1(u)P2(v))**2||Tv||**2 - (Tv.P1(u)P2(v))**2||Tu||**2 | |
582 | // | |
583 | //============================================================================= | |
584 | gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U, | |
873c119f | 585 | Standard_Real& U1, |
586 | Standard_Real& U2, | |
587 | Standard_Real& Dist) const | |
7fd59977 | 588 | { |
589 | gp_Vec2d T; | |
590 | ||
591 | //----------------------------------------------- | |
0d969553 | 592 | // is the polygon reduced to a point or empty? |
7fd59977 | 593 | //----------------------------------------------- |
594 | if (myPolygon.Length() <= 1) { | |
595 | return Extension(U,U1,U2,Dist,T); | |
596 | } | |
597 | ||
598 | //----------------------------------------------- | |
0d969553 | 599 | // test U out of the limits of the polygon. |
7fd59977 | 600 | //----------------------------------------------- |
601 | if (U < myPolygon.First().ParamOnBis()) { | |
602 | return Extension(U,U1,U2,Dist,T); | |
603 | } | |
604 | if (U > myPolygon.Last().ParamOnBis()) { | |
605 | return Extension(U,U1,U2,Dist,T); | |
606 | } | |
607 | ||
608 | //------------------------------------------------------- | |
0d969553 | 609 | // Find start parameter by using <myPolygon>. |
7fd59977 | 610 | //------------------------------------------------------- |
611 | Standard_Integer IntervalIndex = myPolygon.Interval(U); | |
612 | Standard_Real UMin = myPolygon.Value(IntervalIndex ).ParamOnBis(); | |
613 | Standard_Real UMax = myPolygon.Value(IntervalIndex + 1).ParamOnBis(); | |
614 | Standard_Real VMin = myPolygon.Value(IntervalIndex ).ParamOnC2(); | |
615 | Standard_Real VMax = myPolygon.Value(IntervalIndex + 1).ParamOnC2(); | |
616 | Standard_Real Alpha,VInit; | |
617 | ||
618 | if (Abs(UMax - UMin) < gp::Resolution()) { | |
619 | VInit = VMin; | |
620 | } | |
621 | else { | |
622 | Alpha = (U - UMin)/(UMax - UMin); | |
623 | VInit = VMin + Alpha*(VMax - VMin); | |
624 | } | |
625 | ||
626 | U1 = LinkBisCurve(U); | |
627 | Standard_Real VTemp = Min(VMin,VMax); | |
628 | VMax = Max(VMin,VMax); VMin = VTemp; | |
629 | Standard_Boolean Valid = Standard_True; | |
630 | //--------------------------------------------------------------- | |
0d969553 | 631 | // Calculate parameter U2 on curve C2 solution of H(u,v)=0 |
7fd59977 | 632 | //--------------------------------------------------------------- |
633 | gp_Pnt2d P1; | |
634 | gp_Vec2d T1; | |
873c119f | 635 | Standard_Real EpsH = 1.E-9; |
636 | Standard_Real EpsH100 = 1.E-7; | |
7fd59977 | 637 | curve1->D1 (U1,P1,T1); |
638 | gp_Vec2d N1(T1.Y(), - T1.X()); | |
873c119f | 639 | |
7fd59977 | 640 | if ((VMax - VMin) < Precision::PConfusion()) { |
641 | U2 = VInit; | |
642 | } | |
643 | else { | |
644 | Bisector_FunctionH H (curve2,P1,sign1*sign2*T1); | |
645 | Standard_Real FInit; | |
646 | H.Value(VInit,FInit); | |
647 | if (Abs(FInit) < EpsH) { | |
648 | U2 = VInit; | |
649 | } | |
859a47c3 | 650 | else |
651 | { | |
652 | math_BissecNewton aNewSolution(EpsH); | |
653 | aNewSolution.Perform(H, VMin - EpsH100, VMax + EpsH100, 10); | |
654 | ||
655 | if (aNewSolution.IsDone()) | |
656 | { | |
657 | U2 = aNewSolution.Root(); | |
7fd59977 | 658 | } |
859a47c3 | 659 | else |
660 | { | |
873c119f | 661 | math_FunctionRoot SolRoot (H,VInit,EpsH,VMin - EpsH100,VMax + EpsH100); |
859a47c3 | 662 | |
663 | if (SolRoot.IsDone()) | |
873c119f | 664 | U2 = SolRoot.Root(); |
859a47c3 | 665 | else |
666 | Valid = Standard_False; | |
7fd59977 | 667 | } |
668 | } | |
669 | } | |
670 | ||
671 | gp_Pnt2d PBis = pointStart; | |
672 | //---------------- | |
673 | // P(U) = F(U1,U2) | |
674 | //---------------- | |
675 | if (Valid) { | |
676 | gp_Pnt2d P2 = curve2->Value(U2); | |
677 | gp_Vec2d P2P1(P1.X() - P2.X(),P1.Y() - P2.Y()); | |
678 | Standard_Real SquareP2P1 = P2P1.SquareMagnitude(); | |
679 | Standard_Real N1P2P1 = N1.Dot(P2P1); | |
680 | ||
681 | if (P1.IsEqual(P2,Precision::Confusion())) { | |
682 | PBis = P1 ; | |
683 | Dist = 0.0; | |
684 | } | |
685 | else if (N1P2P1*sign1 < 0) { | |
686 | Valid = Standard_False; | |
687 | } | |
688 | else { | |
873c119f | 689 | PBis = P1.Translated(- (0.5*SquareP2P1/N1P2P1)*N1); |
690 | Dist = P1.SquareDistance(PBis); | |
7fd59977 | 691 | } |
692 | } | |
693 | ||
694 | //---------------------------------------------------------------- | |
0d969553 Y |
695 | // If the point is not valid |
696 | // calculate by intersection. | |
7fd59977 | 697 | //---------------------------------------------------------------- |
698 | if (!Valid) { | |
699 | //-------------------------------------------------------------------- | |
0d969553 Y |
700 | // Construction of the bisectrice point curve and of the straight line passing |
701 | // by P1 and carried by the normal. curve2 is limited by VMin and VMax. | |
7fd59977 | 702 | //-------------------------------------------------------------------- |
703 | Standard_Real DMin = Precision::Infinite(); | |
704 | gp_Pnt2d P; | |
705 | Handle(Bisector_BisecPC) BisPC | |
706 | = new Bisector_BisecPC(curve2, P1, sign2, VMin, VMax); | |
707 | Handle(Geom2d_Line) NorLi = new Geom2d_Line (P1,N1); | |
708 | ||
709 | Geom2dAdaptor_Curve ABisPC(BisPC); | |
710 | Geom2dAdaptor_Curve ANorLi(NorLi); | |
711 | //------------------------------------------------------------------------- | |
712 | Geom2dInt_GInter Intersect(ABisPC,ANorLi, | |
873c119f | 713 | Precision::Confusion(),Precision::Confusion()); |
7fd59977 | 714 | //------------------------------------------------------------------------- |
715 | ||
716 | if (Intersect.IsDone() && !Intersect.IsEmpty()) { | |
717 | for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { | |
873c119f | 718 | if (Intersect.Point(i).ParamOnSecond()*sign1 < Precision::PConfusion()) { |
719 | P = Intersect.Point(i).Value(); | |
720 | if (P.SquareDistance(P1) < DMin) { | |
721 | DMin = P.SquareDistance(P1); | |
722 | PBis = P; | |
723 | U2 = BisPC->LinkBisCurve(Intersect.Point(i).ParamOnFirst()); | |
724 | Dist = DMin; | |
725 | } | |
726 | } | |
7fd59977 | 727 | } |
728 | } | |
729 | } | |
730 | return PBis; | |
731 | } | |
732 | ||
733 | //============================================================================= | |
734 | //function : ValueByInt | |
0d969553 Y |
735 | //purpose : CALCULATE THE CURRENT POINT BY INTERSECTION. |
736 | // ------------------------------------------- | |
737 | // Calculate the current point, the distance from the current point | |
738 | // to two curves, the parameters on each curve of the projection of the | |
739 | // current point. | |
740 | // the current point with parameter U is the intersection of the | |
741 | // bissectrice point curve (P1,curve2) and of the straight line | |
742 | // passing through P1 of director vector N1. | |
743 | // P1 is the current point of parameter U on curve1 and N1 the | |
744 | // normal at this point. | |
7fd59977 | 745 | //============================================================================= |
746 | gp_Pnt2d Bisector_BisecCC::ValueByInt (const Standard_Real U, | |
873c119f | 747 | Standard_Real& U1, |
748 | Standard_Real& U2, | |
749 | Standard_Real& Dist) const | |
7fd59977 | 750 | { |
751 | //------------------------------------------------------------------ | |
0d969553 | 752 | // Return point, tangent, normal on C1 at parameter U. |
7fd59977 | 753 | //------------------------------------------------------------------- |
754 | U1 = LinkBisCurve(U); | |
755 | ||
756 | gp_Pnt2d P1,P2,P,PSol; | |
757 | gp_Vec2d Tan1,Tan2; | |
758 | curve1->D1(U1,P1,Tan1); | |
759 | gp_Vec2d N1( Tan1.Y(), - Tan1.X()); | |
873c119f | 760 | |
7fd59977 | 761 | //-------------------------------------------------------------------------- |
0d969553 | 762 | // test confusion of P1 with extremity of curve2. |
7fd59977 | 763 | //-------------------------------------------------------------------------- |
764 | if (P1.Distance(curve2->Value(curve2->FirstParameter())) < Precision::Confusion()) { | |
765 | U2 = curve2->FirstParameter(); | |
766 | curve2->D1(U2,P2,Tan2); | |
767 | if ( isConvex1 && isConvex2 ) { | |
768 | Dist = 0.; | |
769 | return P1; | |
770 | } | |
771 | if (! Tan1.IsParallel(Tan2,Precision::Angular())) { | |
772 | Dist = 0.; | |
773 | return P1; | |
774 | } | |
775 | } | |
776 | if (P1.Distance(curve2->Value(curve2->LastParameter())) < Precision::Confusion()) { | |
777 | U2 = curve2->LastParameter(); | |
778 | curve2->D1(U2,P2,Tan2); | |
779 | if ( isConvex1 && isConvex2 ) { | |
780 | Dist = 0.; | |
781 | return P1; | |
782 | } | |
783 | if (! Tan1.IsParallel(Tan2,Precision::Angular())) { | |
784 | Dist = 0.; | |
785 | return P1; | |
786 | } | |
787 | } | |
788 | ||
789 | Standard_Boolean YaSol = Standard_False; | |
790 | Standard_Real DMin = Precision::Infinite(); | |
791 | Standard_Real USol; | |
792 | Standard_Real EpsMax = 1.E-6; | |
793 | Standard_Real EpsX; | |
794 | Standard_Real EpsH = 1.E-8; | |
795 | Standard_Real DistPP1; | |
796 | Standard_Integer NbSamples =20; | |
797 | Standard_Real UFirstOnC2 = curve2->FirstParameter(); | |
798 | Standard_Real ULastOnC2 = curve2->LastParameter(); | |
873c119f | 799 | |
7fd59977 | 800 | if (!myPolygon.IsEmpty()){ |
801 | if (sign1 == sign2) { ULastOnC2 = myPolygon.Last().ParamOnC2();} | |
802 | else { UFirstOnC2 = myPolygon.Last().ParamOnC2();} | |
803 | } | |
804 | ||
805 | if (Abs(ULastOnC2 - UFirstOnC2) < Precision::PConfusion()/100.) { | |
806 | Dist = Precision::Infinite(); | |
807 | return P1; | |
808 | } | |
809 | ||
810 | DiscretPar(Abs(ULastOnC2 - UFirstOnC2),EpsH,EpsMax,2,20,EpsX,NbSamples); | |
811 | ||
812 | Bisector_FunctionH H (curve2,P1,sign1*sign2*Tan1); | |
813 | math_FunctionRoots SolRoot (H, | |
873c119f | 814 | UFirstOnC2, |
815 | ULastOnC2 , | |
816 | NbSamples, | |
817 | EpsX,EpsH,EpsH); | |
7fd59977 | 818 | if (SolRoot.IsDone()) { |
819 | for (Standard_Integer j = 1; j <= SolRoot.NbSolutions(); j++) { | |
820 | USol = SolRoot.Value(j); | |
821 | gp_Pnt2d P2 = curve2->Value(USol); | |
822 | gp_Vec2d P2P1(P1.X() - P2.X(),P1.Y() - P2.Y()); | |
823 | Standard_Real SquareP2P1 = P2P1.SquareMagnitude(); | |
824 | Standard_Real N1P2P1 = N1.Dot(P2P1); | |
825 | ||
0d969553 | 826 | // Test if the solution is at the proper side of the curves. |
7fd59977 | 827 | if (N1P2P1*sign1 > 0 ) { |
873c119f | 828 | P = P1.Translated(- (0.5*SquareP2P1/N1P2P1)*N1); |
829 | DistPP1 = P1.SquareDistance(P); | |
830 | if (DistPP1 < DMin) { | |
831 | DMin = DistPP1; | |
832 | PSol = P; | |
833 | U2 = USol; | |
834 | YaSol = Standard_True; | |
835 | } | |
7fd59977 | 836 | } |
837 | } | |
838 | } | |
839 | ||
873c119f | 840 | /* |
7fd59977 | 841 | if (!YaSol) { |
873c119f | 842 | //-------------------------------------------------------------------- |
843 | // Construction de la bisectrice point courbe et de la droite passant | |
844 | // par P1 et portee par la normale. | |
845 | //-------------------------------------------------------------------- | |
846 | Handle(Bisector_BisecPC) BisPC | |
847 | = new Bisector_BisecPC(curve2,P1,sign2,2*distMax); | |
848 | //------------------------------- | |
849 | // Test si la bissectrice existe. | |
850 | //------------------------------- | |
851 | if (BisPC->IsEmpty()) { | |
852 | Dist = Precision::Infinite(); | |
853 | PSol = P1; | |
854 | return PSol; | |
855 | } | |
7fd59977 | 856 | |
873c119f | 857 | Handle(Geom2d_Line) NorLi = new Geom2d_Line (P1,N1); |
858 | Geom2dAdaptor_Curve NorLiAd; | |
859 | if (sign1 < 0.) {NorLiAd.Load(NorLi,0. ,distMax);} | |
860 | else {NorLiAd.Load(NorLi,- distMax,0. );} | |
861 | ||
862 | //------------------------------------------------------------------------- | |
863 | Geom2dInt_GInter Intersect(BisPC,NorLiAd, | |
864 | Precision::Confusion(),Precision::Confusion()); | |
865 | //------------------------------------------------------------------------- | |
866 | if (Intersect.IsDone() && !Intersect.IsEmpty()) { | |
867 | for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { | |
868 | if (Intersect.Point(i).ParamOnSecond()*sign1< Precision::PConfusion()) { | |
869 | P = Intersect.Point(i).Value(); | |
870 | DistPP1 = P.SquareDistance(P1); | |
871 | if (DistPP1 < DMin) { | |
872 | DMin = DistPP1; | |
873 | PSol = P; | |
874 | U2 = Intersect.Point(i).ParamOnFirst(); | |
875 | YaSol = Standard_True; | |
876 | } | |
877 | } | |
7fd59977 | 878 | } |
873c119f | 879 | } |
880 | } | |
881 | */ | |
7fd59977 | 882 | |
883 | if (YaSol) { | |
884 | Dist = DMin; | |
885 | //-------------------------------------------------------------- | |
0d969553 | 886 | // Point found => Test curve distance + Angular Test |
7fd59977 | 887 | //--------------------------------------------------------------- |
888 | P2 = curve2->Value(U2); | |
889 | gp_Vec2d PP1(P1.X() - PSol.X(),P1.Y() - PSol.Y()); | |
890 | gp_Vec2d PP2(P2.X() - PSol.X(),P2.Y() - PSol.Y()); | |
873c119f | 891 | |
7fd59977 | 892 | //----------------------------------------------- |
0d969553 | 893 | // Dist = product of norms = distance at the square. |
7fd59977 | 894 | //----------------------------------------------- |
895 | if (PP1.Dot(PP2) > (1. - Precision::Angular())*Dist) { | |
896 | YaSol = Standard_False; | |
897 | } | |
898 | else { | |
899 | if ( !isConvex1 ) { | |
873c119f | 900 | Standard_Real K1 = Curvature(curve1,U1,Precision::Confusion()); |
901 | if (K1 != 0.) { | |
902 | if (Dist > 1/(K1*K1)) YaSol = Standard_False; | |
903 | } | |
7fd59977 | 904 | } |
905 | if (YaSol) { | |
873c119f | 906 | if ( !isConvex2 ) { |
907 | Standard_Real K2 = Curvature(curve2,U2,Precision::Confusion()); | |
908 | if (K2 != 0.) { | |
909 | if (Dist > 1/(K2*K2)) YaSol = Standard_False; | |
910 | } | |
911 | } | |
7fd59977 | 912 | } |
913 | } | |
914 | } | |
915 | if (!YaSol) { | |
916 | Dist = Precision::Infinite(); | |
917 | PSol = P1; | |
918 | } | |
919 | return PSol; | |
920 | } | |
921 | ||
922 | //============================================================================= | |
923 | //function : D0 | |
924 | //purpose : | |
925 | //============================================================================= | |
926 | void Bisector_BisecCC::D0(const Standard_Real U, | |
873c119f | 927 | gp_Pnt2d& P) const |
7fd59977 | 928 | { |
929 | Standard_Real U1,U2,Dist; | |
930 | ||
931 | P = ValueAndDist(U,U1,U2,Dist); | |
932 | } | |
933 | ||
934 | //============================================================================= | |
935 | //function : D1 | |
936 | //purpose : | |
937 | //============================================================================= | |
938 | void Bisector_BisecCC::D1(const Standard_Real U, | |
873c119f | 939 | gp_Pnt2d& P, |
940 | gp_Vec2d& V ) const | |
7fd59977 | 941 | { |
942 | V.SetCoord(0.,0.); | |
943 | gp_Vec2d V2,V3; | |
944 | Values(U,1,P,V,V2,V3); | |
945 | } | |
946 | ||
947 | //============================================================================= | |
948 | //function : D2 | |
949 | //purpose : | |
950 | //============================================================================= | |
951 | void Bisector_BisecCC::D2(const Standard_Real U, | |
873c119f | 952 | gp_Pnt2d& P, |
953 | gp_Vec2d& V1, | |
954 | gp_Vec2d& V2) const | |
7fd59977 | 955 | { |
956 | V1.SetCoord(0.,0.); | |
957 | V2.SetCoord(0.,0.); | |
958 | gp_Vec2d V3; | |
959 | Values(U,2,P,V1,V2,V3); | |
960 | } | |
961 | ||
962 | //============================================================================= | |
963 | //function : D3 | |
964 | //purpose : | |
965 | //============================================================================= | |
966 | void Bisector_BisecCC::D3(const Standard_Real U, | |
873c119f | 967 | gp_Pnt2d& P, |
968 | gp_Vec2d& V1, | |
969 | gp_Vec2d& V2, | |
970 | gp_Vec2d& V3) const | |
7fd59977 | 971 | { |
972 | V1.SetCoord(0.,0.); | |
973 | V2.SetCoord(0.,0.); | |
974 | V3.SetCoord(0.,0.); | |
975 | Values(U,3,P,V1,V2,V3); | |
976 | } | |
977 | ||
978 | //============================================================================= | |
979 | //function : DN | |
980 | //purpose : | |
981 | //============================================================================= | |
982 | gp_Vec2d Bisector_BisecCC::DN(const Standard_Real U, | |
873c119f | 983 | const Standard_Integer N) const |
7fd59977 | 984 | { |
985 | gp_Pnt2d P; | |
986 | gp_Vec2d V1(0.,0.); | |
987 | gp_Vec2d V2(0.,0.); | |
988 | gp_Vec2d V3(0.,0.); | |
989 | Values (U,N,P,V1,V2,V3); | |
990 | switch (N) { | |
873c119f | 991 | case 1 : return V1; |
992 | case 2 : return V2; | |
993 | case 3 : return V3; | |
994 | default: { | |
995 | Standard_NotImplemented::Raise(); | |
996 | } | |
7fd59977 | 997 | } |
998 | return V1; | |
999 | } | |
1000 | ||
1001 | //============================================================================= | |
1002 | //function : Values | |
0d969553 | 1003 | // purpose : the curve can be described by the following equations: |
7fd59977 | 1004 | // |
1005 | // B(u) = F(u,v0) | |
0d969553 | 1006 | // where v0 = Phi(u) is given by H (u,v) = 0. |
7fd59977 | 1007 | // |
0d969553 | 1008 | // with : |
7fd59977 | 1009 | // ||P2(v0)P1(u)||**2 |
1010 | // F(u,v) = P1(u) - 1/2 *----------------* N(u) | |
1011 | // (N(u).P2(v0)P1(u)) | |
1012 | // | |
1013 | // H(u,v) = (Tu.P1(u)P2(v))**2||Tv||**2 - (Tv.P1(u)P2(v))**2||Tu||**2 | |
1014 | // | |
1015 | // => dB(u)/du = dF/du + dF/dv(- dH/du:dH/dv) | |
1016 | // | |
0d969553 Y |
1017 | // Note : tangent to the bisectrice is bissectrice at |
1018 | // tangents T1(u) and T2(v0) | |
7fd59977 | 1019 | // |
1020 | //============================================================================= | |
1021 | void Bisector_BisecCC::Values (const Standard_Real U, | |
873c119f | 1022 | const Standard_Integer N, |
1023 | gp_Pnt2d& P, | |
1024 | gp_Vec2d& V1, | |
1025 | gp_Vec2d& V2, | |
1026 | gp_Vec2d& V3) const | |
7fd59977 | 1027 | { |
1028 | V1 = gp_Vec2d(0.,0.); | |
1029 | V2 = gp_Vec2d(0.,0.); | |
1030 | V3 = gp_Vec2d(0.,0.); | |
1031 | //------------------------------------------------------------------------- | |
0d969553 Y |
1032 | // Calculate the current point on the bisectrice and the parameters on each |
1033 | // curve. | |
7fd59977 | 1034 | //------------------------------------------------------------------------- |
1035 | Standard_Real U0,V0,Dist; | |
873c119f | 1036 | |
7fd59977 | 1037 | //----------------------------------------------- |
0d969553 | 1038 | // is the polygon reduced to a point or empty? |
7fd59977 | 1039 | //----------------------------------------------- |
1040 | if (myPolygon.Length() <= 1) { | |
1041 | P = Extension(U,U0,V0,Dist,V1); | |
1042 | } | |
1043 | if (U < myPolygon.First().ParamOnBis()) { | |
1044 | P = Extension(U,U0,V0,Dist,V1); | |
1045 | return; | |
1046 | } | |
1047 | if (U > myPolygon.Last().ParamOnBis()) { | |
1048 | P = Extension(U,U0,V0,Dist,V1); | |
1049 | return; | |
1050 | } | |
1051 | P = ValueAndDist(U,U0,V0,Dist); | |
1052 | ||
1053 | if (N == 0) return; | |
1054 | //------------------------------------------------------------------ | |
0d969553 | 1055 | // Return point, tangent, normal to C1 by parameter U0. |
7fd59977 | 1056 | //------------------------------------------------------------------- |
0d969553 Y |
1057 | gp_Pnt2d P1 ; // point on C1. |
1058 | gp_Vec2d Tu ; // tangent to C1 by U0. | |
1059 | gp_Vec2d Tuu ; // second derivative to C1 by U0. | |
7fd59977 | 1060 | curve1->D2(U0,P1,Tu,Tuu); |
0d969553 Y |
1061 | gp_Vec2d Nor( - Tu .Y() , Tu .X()); // Normal by U0. |
1062 | gp_Vec2d Nu ( - Tuu.Y() , Tuu.X()); // derivative of the normal by U0. | |
7fd59977 | 1063 | |
1064 | //------------------------------------------------------------------- | |
0d969553 | 1065 | // Return point, tangent, normale to C2 by parameter V0. |
7fd59977 | 1066 | //------------------------------------------------------------------- |
0d969553 Y |
1067 | gp_Pnt2d P2 ; // point on C2. |
1068 | gp_Vec2d Tv ; // tangent to C2 by V. | |
1069 | gp_Vec2d Tvv ; // second derivative to C2 by V. | |
7fd59977 | 1070 | curve2->D2(V0,P2,Tv,Tvv); |
1071 | ||
1072 | gp_Vec2d PuPv(P2.X() - P1.X(), P2.Y() - P1.Y()); | |
1073 | ||
1074 | //----------------------------- | |
0d969553 | 1075 | // Calculate dH/du and dH/dv. |
7fd59977 | 1076 | //----------------------------- |
1077 | Standard_Real TuTu,TvTv,TuTv; | |
1078 | Standard_Real TuPuPv,TvPuPv ; | |
1079 | Standard_Real TuuPuPv,TuTuu ; | |
1080 | Standard_Real TvvPuPv,TvTvv ; | |
1081 | ||
1082 | TuTu = Tu.Dot(Tu) ; TvTv = Tv.Dot(Tv) ; TuTv = Tu.Dot(Tv); | |
1083 | TuPuPv = Tu.Dot(PuPv) ; TvPuPv = Tv.Dot(PuPv); | |
1084 | TuuPuPv = Tuu.Dot(PuPv) ; TuTuu = Tu.Dot(Tuu) ; | |
1085 | TvvPuPv = Tvv.Dot(PuPv) ; TvTvv = Tv.Dot(Tvv) ; | |
1086 | ||
1087 | Standard_Real dHdu = 2*(TuPuPv*(TuuPuPv - TuTu)*TvTv + | |
873c119f | 1088 | TvPuPv*TuTv*TuTu -TuTuu*TvPuPv*TvPuPv); |
7fd59977 | 1089 | Standard_Real dHdv = 2*(TuPuPv*TuTv*TvTv + TvTvv*TuPuPv*TuPuPv - |
873c119f | 1090 | TvPuPv*(TvvPuPv + TvTv)*TuTu); |
7fd59977 | 1091 | |
1092 | //----------------------------- | |
0d969553 | 1093 | // Calculate dF/du and dF/dv. |
7fd59977 | 1094 | //----------------------------- |
1095 | Standard_Real NorPuPv,NuPuPv,NorTv; | |
1096 | Standard_Real A,B,dAdu,dAdv,dBdu,dBdv,BB; | |
873c119f | 1097 | |
7fd59977 | 1098 | NorPuPv = Nor.Dot(PuPv); |
1099 | NuPuPv = Nu .Dot(PuPv); | |
1100 | NorTv = Nor.Dot(Tv) ; | |
1101 | ||
1102 | A = 0.5*PuPv.SquareMagnitude(); | |
1103 | B = - NorPuPv; | |
1104 | BB = B*B; | |
1105 | dAdu = - TuPuPv; | |
1106 | dBdu = - NuPuPv ; | |
1107 | dAdv = TvPuPv; | |
1108 | dBdv = - NorTv; | |
873c119f | 1109 | |
7fd59977 | 1110 | //--------------------------------------- |
1111 | // F(u,v) = Pu - (A(u,v)/B(u,v))*Nor(u) | |
1112 | //---------------------------------------- | |
1113 | if (BB < gp::Resolution()) { | |
1114 | V1 = Tu.Normalized() + Tv.Normalized(); | |
1115 | V1 = 0.5*Tu.SquareMagnitude()*V1; | |
1116 | } | |
1117 | else { | |
1118 | gp_Vec2d dFdu = Tu - (dAdu/B - dBdu*A/BB)*Nor - (A/B)*Nu; | |
1119 | gp_Vec2d dFdv = ( - dAdv/B + dBdv*A/BB)*Nor ; | |
873c119f | 1120 | |
7fd59977 | 1121 | if (Abs(dHdv) > gp::Resolution()) { |
1122 | V1 = dFdu + dFdv*( - dHdu / dHdv ); | |
1123 | } | |
1124 | else { | |
1125 | V1 = Tu; | |
1126 | } | |
1127 | } | |
1128 | if (N == 1) return; | |
1129 | } | |
1130 | ||
1131 | //============================================================================= | |
1132 | //function : Extension | |
0d969553 Y |
1133 | // purpose : Calculate the current point on the extensions |
1134 | // by tangence of the curve. | |
7fd59977 | 1135 | //============================================================================ |
1136 | gp_Pnt2d Bisector_BisecCC::Extension (const Standard_Real U, | |
873c119f | 1137 | Standard_Real& U1, |
1138 | Standard_Real& U2, | |
1139 | Standard_Real& Dist, | |
1140 | gp_Vec2d& T ) const | |
7fd59977 | 1141 | { |
1142 | Bisector_PointOnBis PRef; | |
1143 | gp_Pnt2d P,P1,P2,PBis; | |
1144 | gp_Vec2d T1,Tang; | |
7fd59977 | 1145 | Standard_Real dU = 0.; |
7fd59977 | 1146 | Standard_Boolean ExtensionTangent = Standard_False; |
1147 | ||
1148 | if (myPolygon.Length() == 0) { | |
1149 | //--------------------------------------------- | |
0d969553 | 1150 | // Empty Polygon => segment (pointStart,pointEnd) |
7fd59977 | 1151 | //--------------------------------------------- |
1152 | dU = U - startIntervals.First(); | |
1153 | P = pointStart; | |
1154 | P1 = pointEnd; | |
1155 | U1 = curve1->LastParameter(); | |
1156 | if (sign1 == sign2) { U2 = curve2->FirstParameter();} | |
1157 | else { U2 = curve2->LastParameter() ;} | |
1158 | Tang.SetCoord(P1.X() - P.X(),P1.Y() - P.Y()); | |
1159 | } | |
1160 | else if (U < myPolygon.First().ParamOnBis()) { | |
1161 | PRef = myPolygon.First(); | |
1162 | P = PRef.Point(); | |
1163 | dU = U - PRef.ParamOnBis(); | |
1164 | if (extensionStart) { | |
1165 | //------------------------------------------------------------ | |
0d969553 | 1166 | // extension = segment (pointstart, first point of the polygon.) |
7fd59977 | 1167 | //------------------------------------------------------------ |
1168 | P1 = pointStart; | |
1169 | U1 = curve1->FirstParameter(); | |
1170 | if (sign1 == sign2) { U2 = curve2->LastParameter();} | |
1171 | else { U2 = curve2->FirstParameter();} | |
1172 | Tang.SetCoord(P.X() - P1.X(),P.Y() - P1.Y()); | |
1173 | } | |
1174 | else { | |
1175 | ExtensionTangent = Standard_True; | |
1176 | } | |
1177 | } | |
1178 | else if (U > myPolygon.Last().ParamOnBis()) { | |
1179 | PRef = myPolygon.Last(); | |
1180 | P = PRef.Point(); | |
1181 | dU = U - PRef.ParamOnBis(); | |
1182 | if (extensionEnd) { | |
1183 | //------------------------------------------------------------ | |
0d969553 | 1184 | // extension = segment (last point of the polygon.pointEnd) |
7fd59977 | 1185 | //------------------------------------------------------------ |
1186 | P1 = pointEnd; | |
1187 | U1 = curve1->LastParameter(); | |
1188 | if (sign1 == sign2) { U2 = curve2->LastParameter();} | |
1189 | else { U2 = curve2->FirstParameter();} | |
1190 | Tang.SetCoord(P1.X() - P.X(),P1.Y() - P.Y()); | |
1191 | } | |
1192 | else { | |
1193 | ExtensionTangent = Standard_True; | |
1194 | } | |
1195 | } | |
1196 | ||
1197 | if (ExtensionTangent) { | |
1198 | //----------------------------------------------------------- | |
0d969553 | 1199 | // If the la curve has no a extension, it is extended by tangency |
7fd59977 | 1200 | //------------------------------------------------------------ |
1201 | U1 = PRef.ParamOnC1(); | |
1202 | U2 = PRef.ParamOnC2(); | |
1203 | P2 = curve2->Value(U2); | |
1204 | curve1->D1(U1,P1,T1); | |
1205 | Tang.SetCoord(2*P.X() - P1.X() - P2.X(), 2*P.Y() - P1.Y() - P2.Y()); | |
1206 | if (Tang.Magnitude() < Precision::Confusion()) { | |
1207 | Tang = T1; | |
1208 | } | |
1209 | if (T1.Dot(Tang) < 0.) Tang = - Tang; | |
1210 | } | |
873c119f | 1211 | |
7fd59977 | 1212 | T = Tang.Normalized(); |
1213 | PBis.SetCoord(P.X() + dU*T.X(),P.Y() + dU*T.Y()); | |
1214 | Dist = P1.Distance(PBis); | |
1215 | return PBis; | |
1216 | } | |
1217 | ||
1218 | //============================================================================= | |
1219 | //function : PointByInt | |
1220 | // purpose : | |
1221 | //============================================================================= | |
1222 | static Standard_Boolean PointByInt(const Handle(Geom2d_Curve)& CA, | |
873c119f | 1223 | const Handle(Geom2d_Curve)& CB, |
1224 | const Standard_Real SignA, | |
1225 | const Standard_Real SignB, | |
1226 | const Standard_Real UOnA, | |
1227 | Standard_Real& UOnB, | |
1228 | Standard_Real& Dist) | |
7fd59977 | 1229 | { |
1230 | //------------------------------------------------------------------ | |
0d969553 | 1231 | // Return point,tangent, normal on CA with parameter UOnA. |
7fd59977 | 1232 | //------------------------------------------------------------------- |
1233 | gp_Pnt2d P1,P2,P,PSol; | |
1234 | gp_Vec2d Tan1,Tan2; | |
1235 | Standard_Boolean IsConvexA = Bisector::IsConvex(CA,SignA); | |
1236 | Standard_Boolean IsConvexB = Bisector::IsConvex(CB,SignB); | |
1237 | ||
1238 | CA->D1(UOnA,P1,Tan1); | |
1239 | gp_Vec2d N1(Tan1.Y(), - Tan1.X()); | |
873c119f | 1240 | |
7fd59977 | 1241 | //-------------------------------------------------------------------------- |
0d969553 | 1242 | // test of confusion of P1 with extremity of curve2. |
7fd59977 | 1243 | //-------------------------------------------------------------------------- |
1244 | if (P1.Distance(CB->Value(CB->FirstParameter())) < Precision::Confusion()) { | |
1245 | UOnB = CB->FirstParameter(); | |
1246 | CB->D1(UOnB,P2,Tan2); | |
1247 | if ( IsConvexA && IsConvexB ) { | |
1248 | Dist = 0.; | |
1249 | return Standard_True; | |
1250 | } | |
1251 | if (! Tan1.IsParallel(Tan2,Precision::Angular())) { | |
1252 | Dist = 0.; | |
1253 | return Standard_False; | |
1254 | } | |
1255 | } | |
1256 | if (P1.Distance(CB->Value(CB->LastParameter())) < Precision::Confusion()) { | |
1257 | UOnB = CB->LastParameter(); | |
1258 | CB->D1(UOnB,P2,Tan2); | |
1259 | if ( IsConvexA && IsConvexB ) { | |
1260 | Dist = 0.; | |
1261 | return Standard_True; | |
1262 | } | |
1263 | if (! Tan1.IsParallel(Tan2,Precision::Angular())) { | |
1264 | Dist = 0.; | |
1265 | return Standard_False; | |
1266 | } | |
1267 | } | |
1268 | ||
1269 | Standard_Real DMin = Precision::Infinite(); | |
1270 | Standard_Real UPC; | |
1271 | Standard_Boolean YaSol = Standard_False; | |
873c119f | 1272 | //-------------------------------------------------------------------- |
0d969553 Y |
1273 | // Construction of the bisectrice point curve and of the straight line passing |
1274 | // through P1 and carried by the normal. | |
7fd59977 | 1275 | //-------------------------------------------------------------------- |
1276 | Handle(Bisector_BisecPC) BisPC | |
1277 | = new Bisector_BisecPC(CB,P1,SignB ); | |
1278 | //------------------------------- | |
0d969553 | 1279 | // Test if the bissectrice exists. |
7fd59977 | 1280 | //------------------------------- |
1281 | if (BisPC->IsEmpty()) { | |
1282 | Dist = Precision::Infinite(); | |
1283 | PSol = P1; | |
1284 | return Standard_False; | |
1285 | } | |
1286 | ||
1287 | Handle(Geom2d_Line) NorLi = new Geom2d_Line (P1,N1); | |
1288 | ||
1289 | Geom2dAdaptor_Curve ABisPC(BisPC); | |
1290 | Geom2dAdaptor_Curve ANorLi(NorLi); | |
1291 | //------------------------------------------------------------------------- | |
1292 | Geom2dInt_GInter Intersect(ABisPC,ANorLi, | |
873c119f | 1293 | Precision::Confusion(),Precision::Confusion()); |
7fd59977 | 1294 | //------------------------------------------------------------------------- |
1295 | ||
1296 | if (Intersect.IsDone() && !Intersect.IsEmpty()) { | |
1297 | for (Standard_Integer i = 1; i <= Intersect.NbPoints(); i++) { | |
1298 | if (Intersect.Point(i).ParamOnSecond()*SignA < Precision::PConfusion()) { | |
873c119f | 1299 | P = Intersect.Point(i).Value(); |
1300 | if (P.SquareDistance(P1) < DMin) { | |
1301 | DMin = P.SquareDistance(P1); | |
1302 | PSol = P; | |
1303 | UPC = Intersect.Point(i).ParamOnFirst(); | |
1304 | UOnB = BisPC->LinkBisCurve(UPC); | |
1305 | Dist = DMin; | |
1306 | YaSol = Standard_True; | |
1307 | } | |
7fd59977 | 1308 | } |
1309 | } | |
1310 | } | |
1311 | if (YaSol) { | |
1312 | //-------------------------------------------------------------- | |
0d969553 | 1313 | // Point found => Test distance curvature + Angular test |
7fd59977 | 1314 | //--------------------------------------------------------------- |
1315 | P2 = CB->Value(UOnB); | |
873c119f | 1316 | if(P1.SquareDistance(PSol) < 1.e-32) |
1317 | { | |
1318 | YaSol = Standard_False; | |
1319 | return YaSol; | |
1320 | } | |
1321 | if(P2.SquareDistance(PSol) < 1.e-32) | |
1322 | { | |
1323 | YaSol = Standard_False; | |
1324 | return YaSol; | |
1325 | } | |
1326 | ||
7fd59977 | 1327 | gp_Dir2d PP1Unit(P1.X() - PSol.X(),P1.Y() - PSol.Y()); |
1328 | gp_Dir2d PP2Unit(P2.X() - PSol.X(),P2.Y() - PSol.Y()); | |
873c119f | 1329 | |
7fd59977 | 1330 | if (PP1Unit*PP2Unit > 1. - Precision::Angular()) { |
1331 | YaSol = Standard_False; | |
1332 | } | |
1333 | else { | |
1334 | Dist = sqrt(Dist); | |
1335 | if ( !IsConvexA ) { | |
873c119f | 1336 | Standard_Real K1 = Curvature(CA,UOnA,Precision::Confusion()); |
1337 | if (K1 != 0.) { | |
1338 | if (Dist > Abs(1/K1)) YaSol = Standard_False; | |
1339 | } | |
7fd59977 | 1340 | } |
1341 | if (YaSol) { | |
873c119f | 1342 | if ( !IsConvexB ) { |
1343 | Standard_Real K2 = Curvature(CB,UOnB,Precision::Confusion()); | |
1344 | if (K2 != 0.) { | |
1345 | if (Dist > Abs(1/K2)) YaSol = Standard_False; | |
1346 | } | |
1347 | } | |
7fd59977 | 1348 | } |
1349 | } | |
1350 | } | |
1351 | return YaSol; | |
1352 | } | |
1353 | ||
1354 | //============================================================================= | |
1355 | //function : SupLastParameter | |
1356 | // purpose : | |
1357 | //============================================================================= | |
1358 | void Bisector_BisecCC::SupLastParameter() | |
1359 | { | |
1360 | endIntervals.Append(curve1->LastParameter()); | |
1361 | // ---------------------------------------------------------------------- | |
0d969553 Y |
1362 | // Calculate parameter on curve1 associated to one or the other of the extremities |
1363 | // of curve2 following the values of sign1 and sign2. | |
1364 | // the bissectrice is limited by the obtained parameters. | |
7fd59977 | 1365 | //------------------------------------------------------------------------ |
1366 | Standard_Real UOnC1,UOnC2,Dist; | |
1367 | if (sign1 == sign2) { | |
1368 | UOnC2 = curve2->FirstParameter(); | |
1369 | } | |
1370 | else { | |
1371 | UOnC2 = curve2->LastParameter(); | |
1372 | } | |
1373 | Standard_Boolean YaSol = PointByInt(curve2,curve1,sign2,sign1,UOnC2,UOnC1,Dist); | |
1374 | if (YaSol) { | |
1375 | if (UOnC1 > startIntervals.First() && UOnC1 < endIntervals.Last()) { | |
1376 | endIntervals.SetValue(1,UOnC1); | |
1377 | } | |
1378 | } | |
1379 | } | |
1380 | ||
1381 | //============================================================================= | |
1382 | //function : Curve | |
1383 | // purpose : | |
1384 | //============================================================================= | |
1385 | Handle(Geom2d_Curve) Bisector_BisecCC::Curve(const Standard_Integer I) const | |
1386 | { | |
1387 | if (I == 1) return curve1; | |
1388 | else if (I == 2) return curve2; | |
1389 | else Standard_OutOfRange::Raise(); | |
1390 | return curve1; | |
1391 | } | |
1392 | ||
1393 | //============================================================================= | |
1394 | //function : LinkBisCurve | |
1395 | //purpose : | |
1396 | //============================================================================= | |
1397 | Standard_Real Bisector_BisecCC::LinkBisCurve(const Standard_Real U) const | |
1398 | { | |
1399 | return (U - shiftParameter); | |
1400 | } | |
1401 | ||
1402 | //============================================================================= | |
1403 | //function : LinkCurveBis | |
1404 | //purpose : | |
1405 | //============================================================================= | |
1406 | Standard_Real Bisector_BisecCC::LinkCurveBis(const Standard_Real U) const | |
1407 | { | |
1408 | return (U + shiftParameter); | |
1409 | } | |
1410 | ||
1411 | //============================================================================= | |
1412 | //function : Indent | |
1413 | //purpose : | |
1414 | //============================================================================= | |
1415 | static void Indent(const Standard_Integer Offset) { | |
1416 | if (Offset > 0) { | |
1417 | for (Standard_Integer i = 0; i < Offset; i++) {cout << " ";} | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | //============================================================================= | |
1422 | //function : Polygon | |
1423 | // purpose : | |
1424 | //============================================================================= | |
1425 | const Bisector_PolyBis& Bisector_BisecCC::Polygon() const | |
1426 | { | |
1427 | return myPolygon; | |
1428 | } | |
1429 | ||
1430 | //========================================================================== | |
1431 | //function : Parameter | |
1432 | //purpose : | |
1433 | //========================================================================== | |
1434 | Standard_Real Bisector_BisecCC::Parameter(const gp_Pnt2d& P) const | |
1435 | { | |
1436 | Standard_Real UOnCurve; | |
1437 | ||
1438 | if (P.IsEqual(Value(FirstParameter()),Precision::Confusion())) { | |
1439 | UOnCurve = FirstParameter(); | |
1440 | } | |
1441 | else if (P.IsEqual(Value(LastParameter()),Precision::Confusion())) { | |
1442 | UOnCurve = LastParameter(); | |
1443 | } | |
91bb31f3 | 1444 | else |
1445 | { | |
1446 | ProjOnCurve(P, curve1, UOnCurve); | |
7fd59977 | 1447 | } |
91bb31f3 | 1448 | |
7fd59977 | 1449 | return UOnCurve; |
1450 | } | |
1451 | ||
1452 | ||
1453 | //============================================================================= | |
1454 | //function : Dump | |
1455 | // purpose : | |
1456 | //============================================================================= | |
1457 | //void Bisector_BisecCC::Dump(const Standard_Integer Deep, | |
1458 | void Bisector_BisecCC::Dump(const Standard_Integer , | |
873c119f | 1459 | const Standard_Integer Offset) const |
7fd59977 | 1460 | { |
1461 | Indent (Offset); | |
1462 | cout <<"Bisector_BisecCC :"<<endl; | |
1463 | Indent (Offset); | |
873c119f | 1464 | // cout <<"Curve1 :"<<curve1<<endl; |
1465 | // cout <<"Curve2 :"<<curve2<<endl; | |
7fd59977 | 1466 | cout <<"Sign1 :"<<sign1<<endl; |
1467 | cout <<"Sign2 :"<<sign2<<endl; | |
1468 | ||
1469 | cout <<"Number Of Intervals :"<<startIntervals.Length()<<endl; | |
1470 | for (Standard_Integer i = 1; i <= startIntervals.Length(); i++) { | |
1471 | cout <<"Interval number :"<<i<<"Start :"<<startIntervals.Value(i) | |
873c119f | 1472 | <<" end :"<< endIntervals.Value(i)<<endl ; |
7fd59977 | 1473 | } |
1474 | cout <<"Index Current Interval :"<<currentInterval<<endl; | |
1475 | } | |
1476 | ||
1477 | //============================================================================= | |
1478 | //function : Curve | |
1479 | // purpose : | |
1480 | //============================================================================= | |
1481 | void Bisector_BisecCC::Curve(const Standard_Integer I, | |
873c119f | 1482 | const Handle(Geom2d_Curve)& C) |
7fd59977 | 1483 | { |
1484 | if (I == 1) curve1 = C; | |
1485 | else if (I == 2) curve2 = C; | |
1486 | else Standard_OutOfRange::Raise(); | |
1487 | } | |
1488 | ||
1489 | //============================================================================= | |
1490 | //function : Sign | |
1491 | // purpose : | |
1492 | //============================================================================= | |
1493 | void Bisector_BisecCC::Sign(const Standard_Integer I, | |
873c119f | 1494 | const Standard_Real S) |
7fd59977 | 1495 | { |
1496 | if (I == 1) sign1 = S; | |
1497 | else if (I == 2) sign2 = S; | |
1498 | else Standard_OutOfRange::Raise(); | |
1499 | } | |
1500 | ||
1501 | //============================================================================= | |
1502 | //function : Polygon | |
1503 | // purpose : | |
1504 | //============================================================================= | |
1505 | void Bisector_BisecCC::Polygon(const Bisector_PolyBis& P) | |
1506 | { | |
1507 | myPolygon = P; | |
1508 | } | |
1509 | ||
1510 | //============================================================================= | |
1511 | //function : DistMax | |
1512 | // purpose : | |
1513 | //============================================================================= | |
1514 | void Bisector_BisecCC::DistMax(const Standard_Real D) | |
1515 | { | |
1516 | distMax = D; | |
1517 | } | |
1518 | ||
1519 | //============================================================================= | |
1520 | //function : IsConvex | |
1521 | // purpose : | |
1522 | //============================================================================= | |
1523 | void Bisector_BisecCC::IsConvex(const Standard_Integer I, | |
873c119f | 1524 | const Standard_Boolean IsConvex) |
7fd59977 | 1525 | { |
1526 | if (I == 1) isConvex1 = IsConvex; | |
1527 | else if (I == 2) isConvex2 = IsConvex; | |
1528 | else Standard_OutOfRange::Raise(); | |
1529 | } | |
1530 | ||
1531 | //============================================================================= | |
1532 | //function : IsEmpty | |
1533 | // purpose : | |
1534 | //============================================================================= | |
1535 | void Bisector_BisecCC::IsEmpty ( const Standard_Boolean IsEmpty) | |
1536 | { | |
1537 | isEmpty = IsEmpty; | |
1538 | } | |
1539 | ||
1540 | //============================================================================= | |
1541 | //function : ExtensionStart | |
1542 | // purpose : | |
1543 | //============================================================================= | |
1544 | void Bisector_BisecCC::ExtensionStart( const Standard_Boolean ExtensionStart) | |
1545 | { | |
1546 | extensionStart = ExtensionStart; | |
1547 | } | |
1548 | ||
1549 | //============================================================================= | |
1550 | //function : ExtensionEnd | |
1551 | // purpose : | |
1552 | //============================================================================= | |
1553 | void Bisector_BisecCC::ExtensionEnd( const Standard_Boolean ExtensionEnd) | |
1554 | { | |
1555 | extensionEnd = ExtensionEnd; | |
1556 | } | |
1557 | ||
1558 | //============================================================================= | |
1559 | //function : PointStart | |
1560 | // purpose : | |
1561 | //============================================================================= | |
1562 | void Bisector_BisecCC::PointStart( const gp_Pnt2d& Point) | |
1563 | { | |
1564 | pointStart = Point; | |
1565 | } | |
1566 | ||
1567 | //============================================================================= | |
1568 | //function : PointEnd | |
1569 | // purpose : | |
1570 | //============================================================================= | |
1571 | void Bisector_BisecCC::PointEnd( const gp_Pnt2d& Point) | |
1572 | { | |
1573 | pointEnd = Point; | |
1574 | } | |
1575 | ||
1576 | //============================================================================= | |
1577 | //function : StartIntervals | |
1578 | // purpose : | |
1579 | //============================================================================= | |
1580 | void Bisector_BisecCC::StartIntervals | |
1581 | (const TColStd_SequenceOfReal& StartIntervals) | |
1582 | { | |
1583 | startIntervals = StartIntervals; | |
1584 | } | |
1585 | ||
1586 | //============================================================================= | |
1587 | //function : EndIntervals | |
1588 | // purpose : | |
1589 | //============================================================================= | |
1590 | void Bisector_BisecCC::EndIntervals | |
1591 | (const TColStd_SequenceOfReal& EndIntervals) | |
1592 | { | |
1593 | endIntervals = EndIntervals; | |
1594 | } | |
1595 | ||
1596 | //============================================================================= | |
1597 | //function : FirstParameter | |
1598 | // purpose : | |
1599 | //============================================================================= | |
1600 | void Bisector_BisecCC::FirstParameter (const Standard_Real U) | |
1601 | { | |
1602 | startIntervals.Append(U); | |
1603 | } | |
1604 | ||
1605 | //============================================================================= | |
1606 | //function : LastParameter | |
1607 | // purpose : | |
1608 | //============================================================================= | |
1609 | void Bisector_BisecCC::LastParameter (const Standard_Real U) | |
1610 | { | |
1611 | endIntervals.Append(U); | |
1612 | } | |
1613 | ||
1614 | //============================================================================= | |
1615 | //function : SearchBound | |
1616 | // purpose : | |
1617 | //============================================================================= | |
1618 | Standard_Real Bisector_BisecCC::SearchBound (const Standard_Real U1, | |
873c119f | 1619 | const Standard_Real U2) const |
7fd59977 | 1620 | { |
1621 | Standard_Real UMid,Dist1,Dist2,DistMid,U11,U22; | |
1622 | Standard_Real UC1,UC2; | |
1623 | gp_Pnt2d PBis,PBisPrec; | |
1624 | Standard_Real TolPnt = Precision::Confusion(); | |
1625 | Standard_Real TolPar = Precision::PConfusion(); | |
1626 | U11 = U1; U22 = U2; | |
1627 | PBisPrec = ValueByInt(U11,UC1,UC2,Dist1); | |
1628 | PBis = ValueByInt(U22,UC1,UC2,Dist2); | |
873c119f | 1629 | |
7fd59977 | 1630 | while ((U22 - U11) > TolPar || |
873c119f | 1631 | ((Dist1 < Precision::Infinite() && |
1632 | Dist2 < Precision::Infinite() && | |
1633 | !PBis.IsEqual(PBisPrec,TolPnt)))) { | |
1634 | PBisPrec = PBis; | |
1635 | UMid = 0.5*( U22 + U11); | |
1636 | PBis = ValueByInt(UMid,UC1,UC2,DistMid); | |
1637 | if ((Dist1 < Precision::Infinite()) == (DistMid < Precision::Infinite())) { | |
1638 | U11 = UMid; | |
1639 | Dist1 = DistMid; | |
1640 | } | |
1641 | else { | |
1642 | U22 = UMid; | |
1643 | Dist2 = DistMid; | |
1644 | } | |
7fd59977 | 1645 | } |
1646 | PBis = ValueByInt(U11,UC1,UC2,Dist1); | |
1647 | if (Dist1 < Precision::Infinite()) { | |
1648 | UMid = U11; | |
1649 | } | |
1650 | else { | |
1651 | UMid = U22; | |
1652 | } | |
1653 | return UMid; | |
1654 | } | |
1655 | ||
1656 | //============================================================================= | |
1657 | //function : ProjOnCurve | |
1658 | // purpose : | |
1659 | //============================================================================= | |
91bb31f3 | 1660 | static Standard_Boolean ProjOnCurve (const gp_Pnt2d& P, |
873c119f | 1661 | const Handle(Geom2d_Curve)& C, |
1662 | Standard_Real& theParam) | |
7a06c690 | 1663 | { |
91bb31f3 | 1664 | //Standard_Real UOnCurve =0.; |
1665 | theParam = 0.0; | |
7fd59977 | 1666 | gp_Pnt2d PF,PL; |
1667 | gp_Vec2d TF,TL; | |
1668 | ||
1669 | C->D1(C->FirstParameter(),PF,TF); | |
1670 | C->D1(C->LastParameter() ,PL,TL); | |
1671 | ||
91bb31f3 | 1672 | if (P.IsEqual(PF ,Precision::Confusion())) |
1673 | { | |
1674 | theParam = C->FirstParameter(); | |
1675 | return Standard_True; | |
7fd59977 | 1676 | } |
873c119f | 1677 | |
91bb31f3 | 1678 | if (P.IsEqual(PL ,Precision::Confusion())) |
1679 | { | |
1680 | theParam = C->LastParameter(); | |
1681 | return Standard_True; | |
7fd59977 | 1682 | } |
873c119f | 1683 | |
7fd59977 | 1684 | gp_Vec2d PPF(PF.X() - P.X(), PF.Y() - P.Y()); |
1685 | TF.Normalize(); | |
873c119f | 1686 | |
91bb31f3 | 1687 | if ( Abs (PPF.Dot(TF)) < Precision::Confusion()) |
1688 | { | |
1689 | theParam = C->FirstParameter(); | |
1690 | return Standard_True; | |
7fd59977 | 1691 | } |
1692 | gp_Vec2d PPL (PL.X() - P.X(), PL.Y() - P.Y()); | |
1693 | TL.Normalize(); | |
91bb31f3 | 1694 | if ( Abs (PPL.Dot(TL)) < Precision::Confusion()) |
1695 | { | |
1696 | theParam = C->LastParameter(); | |
1697 | return Standard_True; | |
7fd59977 | 1698 | } |
1699 | Geom2dAPI_ProjectPointOnCurve Proj(P,C, | |
873c119f | 1700 | C->FirstParameter(), |
1701 | C->LastParameter()); | |
7fd59977 | 1702 | if (Proj.NbPoints() > 0) { |
91bb31f3 | 1703 | theParam = Proj.LowerDistanceParameter(); |
7fd59977 | 1704 | } |
1705 | else { | |
91bb31f3 | 1706 | return Standard_False; |
7fd59977 | 1707 | } |
91bb31f3 | 1708 | |
1709 | return Standard_True; | |
7fd59977 | 1710 | } |
1711 | ||
1712 | //============================================================================= | |
1713 | //function : TestExtension | |
1714 | // purpose : | |
1715 | //============================================================================= | |
1716 | static Standard_Boolean TestExtension (const Handle(Geom2d_Curve)& C1, | |
873c119f | 1717 | const Handle(Geom2d_Curve)& C2, |
1718 | const Standard_Integer Start_End) | |
7fd59977 | 1719 | { |
1720 | gp_Pnt2d P1,P2; | |
1721 | gp_Vec2d T1,T2; | |
1722 | Standard_Boolean Test = Standard_False; | |
1723 | if (Start_End == 1) { | |
1724 | C1->D1(C1->FirstParameter(),P1,T1); | |
1725 | } | |
1726 | else { | |
1727 | C1->D1(C1->LastParameter(),P1,T1); | |
1728 | } | |
1729 | C2->D1(C2->FirstParameter(),P2,T2); | |
1730 | if (P1.IsEqual(P2,Precision::Confusion())) { | |
1731 | T1.Normalize(); T2.Normalize(); | |
1732 | if (T1.Dot(T2) > 1.0 - Precision::Confusion()) { | |
1733 | Test = Standard_True; | |
1734 | } | |
1735 | } | |
1736 | else { | |
1737 | C2->D1(C2->LastParameter(),P2,T2); | |
1738 | if (P1.IsEqual(P2,Precision::Confusion())) { | |
1739 | T2.Normalize(); | |
1740 | if (T1.Dot(T2) > 1.0 - Precision::Confusion()) { | |
873c119f | 1741 | Test = Standard_True; |
7fd59977 | 1742 | } |
1743 | } | |
1744 | } | |
1745 | return Test; | |
1746 | } | |
1747 | ||
1748 | //============================================================================= | |
1749 | //function : ComputePointEnd | |
1750 | // purpose : | |
1751 | //============================================================================= | |
1752 | void Bisector_BisecCC::ComputePointEnd () | |
1753 | { | |
1754 | Standard_Real U1,U2; | |
1755 | Standard_Real KC,RC; | |
1756 | U1 = curve1->FirstParameter(); | |
1757 | if (sign1 == sign2) { | |
1758 | U2 = curve2->LastParameter(); | |
1759 | } | |
1760 | else { | |
1761 | U2 = curve2->FirstParameter(); | |
1762 | } | |
1763 | Standard_Real K1 = Curvature(curve1,U1,Precision::Confusion()); | |
1764 | Standard_Real K2 = Curvature(curve2,U2,Precision::Confusion()); | |
1765 | if (!isConvex1 && !isConvex2) { | |
1766 | if (K1 < K2) {KC = K1;} else {KC = K2;} | |
1767 | } | |
1768 | else if (!isConvex1) {KC = K1;} | |
1769 | else {KC = K2;} | |
1770 | ||
1771 | gp_Pnt2d PF; | |
1772 | gp_Vec2d TF; | |
1773 | curve1->D1(U1,PF,TF); | |
1774 | TF.Normalize(); | |
1775 | if (KC != 0.) { RC = Abs(1/KC);} | |
1776 | else { RC = Precision::Infinite();} | |
1777 | pointEnd.SetCoord(PF.X() - sign1*RC*TF.Y(), PF.Y() + sign1*RC*TF.X()); | |
1778 | ||
1779 | } | |
1780 | ||
1781 | //============================================================================= | |
1782 | //function : DiscretPar | |
1783 | // purpose : | |
1784 | //============================================================================= | |
1785 | static Standard_Boolean DiscretPar(const Standard_Real DU, | |
873c119f | 1786 | const Standard_Real EpsMin, |
1787 | const Standard_Real EpsMax, | |
1788 | const Standard_Integer NbMin, | |
1789 | const Standard_Integer NbMax, | |
1790 | Standard_Real& Eps, | |
1791 | Standard_Integer& Nb) | |
7fd59977 | 1792 | { |
1793 | if (DU <= NbMin*EpsMin) { | |
1794 | Eps = DU/(NbMin + 1) ; | |
1795 | Nb = NbMin; | |
1796 | return Standard_False; | |
1797 | } | |
1798 | ||
1799 | Eps = Min (EpsMax,DU/NbMax); | |
1800 | ||
1801 | if (Eps < EpsMin) { | |
1802 | Eps = EpsMin; | |
1803 | Nb = Standard_Integer(DU/EpsMin); | |
1804 | } | |
1805 | else { Nb = NbMax;} | |
1806 | ||
1807 | return Standard_True; | |
1808 | } | |
1809 | ||
1810 |