1 // Created on: 1993-01-29
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 //-- lbr le 12 juin : Ajout des fleches sur les Lines
23 //-- msv 13.03.2002 : compute deflection for WLine; Error() returns deflection
25 #include <IntPatch_PolyLine.ixx>
27 #include <Precision.hxx>
29 #define INITDEFLE Precision::PConfusion()*100.
31 //=======================================================================
32 //function : IntPatch_PolyLine
34 //=======================================================================
36 IntPatch_PolyLine::IntPatch_PolyLine ()
37 : IntPatch_Polygo(INITDEFLE)
40 //=======================================================================
41 //function : IntPatch_PolyLine
43 //=======================================================================
45 IntPatch_PolyLine::IntPatch_PolyLine (const Standard_Real InitDefle)
46 : IntPatch_Polygo(InitDefle)
49 //=======================================================================
52 //=======================================================================
54 void IntPatch_PolyLine::SetWLine(const Standard_Boolean OnFirst, const Handle(IntPatch_WLine)& Line)
56 typ = IntPatch_Walking;
62 //=======================================================================
65 //=======================================================================
67 void IntPatch_PolyLine::SetRLine(const Standard_Boolean OnFirst, const Handle(IntPatch_RLine)& Line)
69 typ = IntPatch_Restriction;
75 //=======================================================================
78 //=======================================================================
80 void IntPatch_PolyLine::Prepare()
84 Standard_Integer n=NbPoints();
85 const Standard_Real eps_2 = myError * myError;
89 P1 = Point(1); P2 = Point(2);
91 for (i=1; i<=n ;i++) {
92 const gp_Pnt2d& P3 = Point(i);
94 gp_XY V13 = P3.XY() - P1.XY();
95 gp_XY V12 = P2.XY() - P1.XY();
96 Standard_Real d13_2 = V13.SquareModulus(), d_2;
98 d_2 = V13.CrossSquareMagnitude(V12) / d13_2;
101 if (d_2 > myError * myError) {
102 // try to compute deflection more precisely using parabola interpolation
103 gp_XY V23 = P3.XY() - P2.XY();
104 Standard_Real d12 = V12.Modulus(), d23 = V23.Modulus();
105 // compute parameter of P2 (assume parameters of P1,P3 are 0,1)
106 Standard_Real tm = d12 / (d12+d23);
107 if (tm > 0.1 && tm < 0.9) {
108 tm -= (tm-0.5) * 0.6;
109 Standard_Real tm1mtm = tm*(1-tm);
110 // coefficients of parabola
111 Standard_Real Ax = (tm*V13.X() - V12.X()) / tm1mtm;
112 Standard_Real Bx = (V12.X() - tm*tm*V13.X()) / tm1mtm;
113 Standard_Real Cx = P1.X();
114 Standard_Real Ay = (tm*V13.Y() - V12.Y()) / tm1mtm;
115 Standard_Real By = (V12.Y() - tm*tm*V13.Y()) / tm1mtm;
116 Standard_Real Cy = P1.Y();
117 // equations of lines P1-P2 and P2-P3
118 Standard_Real A1 = V12.Y() / d12;
119 Standard_Real B1 = -V12.X() / d12;
120 Standard_Real C1 = (P2.X()*P1.Y() - P1.X()*P2.Y()) / d12;
121 Standard_Real A2 = V23.Y() / d23;
122 Standard_Real B2 = -V23.X() / d23;
123 Standard_Real C2 = (P3.X()*P2.Y() - P2.X()*P3.Y()) / d23;
124 // points on parabola with max deflection
125 Standard_Real t1 = -0.5 * (A1*Bx + B1*By) / (A1*Ax + B1*Ay);
126 Standard_Real t2 = -0.5 * (A2*Bx + B2*By) / (A2*Ax + B2*Ay);
127 Standard_Real xt1 = Ax*t1*t1 + Bx*t1 + Cx;
128 Standard_Real yt1 = Ay*t1*t1 + By*t1 + Cy;
129 Standard_Real xt2 = Ax*t2*t2 + Bx*t2 + Cx;
130 Standard_Real yt2 = Ay*t2*t2 + By*t2 + Cy;
131 // max deflection on segments P1-P2 and P2-P3
132 Standard_Real d1 = Abs (A1*xt1 + B1*yt1 + C1);
133 Standard_Real d2 = Abs (A2*xt2 + B2*yt2 + C2);
134 if (d2 > d1) d1 = d2;
135 // select min deflection from linear and parabolic ones
136 if (d1 * d1 < d_2) d_2 = d1 * d1;
138 if (d_2 > myError * myError) myError=Sqrt(d_2);
144 myBox.Enlarge(myError);
147 //=======================================================================
148 //function : ResetError
150 //=======================================================================
152 void IntPatch_PolyLine::ResetError()
157 //=======================================================================
158 //function : NbPoints
160 //=======================================================================
162 Standard_Integer IntPatch_PolyLine::NbPoints() const
164 return (typ == IntPatch_Walking ? wpoly->NbPnts() : rpoly->NbPnts());
167 //=======================================================================
170 //=======================================================================
172 gp_Pnt2d IntPatch_PolyLine::Point(const Standard_Integer Index ) const
174 Standard_Real X,Y,X1,Y1,DX,DY;
177 if (typ == IntPatch_Walking) {
178 wpoly->Point(Index).ParametersOnS1(X,Y);
180 wpoly->Point(2).ParametersOnS1(X1,Y1);
184 else if(Index==wpoly->NbPnts()) {
185 wpoly->Point(Index-1).ParametersOnS1(X1,Y1);
191 rpoly->Point(Index).ParametersOnS1(X,Y);
195 if (typ == IntPatch_Walking) {
196 wpoly->Point(Index).ParametersOnS2(X,Y);
198 wpoly->Point(2).ParametersOnS2(X1,Y1);
202 else if(Index==wpoly->NbPnts()) {
203 wpoly->Point(Index-1).ParametersOnS2(X1,Y1);
209 rpoly->Point(Index).ParametersOnS2(X,Y);
213 return(gp_Pnt2d(X+DX,Y+DY));