1 // File: GeomFill_DraftTrihedron.cxx
2 // Created: Wed Apr 15 14:59:31 1998
3 // Author: Stephanie HUMEAU
7 #include <GeomFill_DraftTrihedron.ixx>
9 #include <Precision.hxx>
10 #include <GeomAbs_CurveType.hxx>
11 #include <Adaptor3d_HCurve.hxx>
13 //=======================================================================
15 //purpose : computes (F/|F|)''
16 //=======================================================================
17 static gp_Vec DDeriv(const gp_Vec& F, const gp_Vec& DF, const gp_Vec& D2F)
19 Standard_Real Norma = F.Magnitude();
21 Standard_Real dot = F.Dot(DF);
25 gp_Vec Result = (D2F - 2*DF*(F*DF)/(Norma*Norma))/Norma -
26 F*((DF.SquareMagnitude() + F*D2F
27 - 3*(F*DF)*(F*DF)/(Norma*Norma))/(Norma*Norma*Norma));
31 //=======================================================================
32 //function : DraftTrihedron
33 //purpose : Constructor
34 //=======================================================================
35 GeomFill_DraftTrihedron::GeomFill_DraftTrihedron(const gp_Vec& BiNormal,
36 const Standard_Real Angle)
44 //=======================================================================
47 //=======================================================================
48 void GeomFill_DraftTrihedron::SetAngle(const Standard_Real Angle)
50 myAngle = PI/2 + Angle;
55 //=======================================================================
57 //purpose : calculation of trihedron
58 //=======================================================================
59 Standard_Boolean GeomFill_DraftTrihedron::D0(const Standard_Real Param,
66 myTrimmed->D1(Param,P,T);
69 gp_Vec b = T.Crossed(B);
70 Standard_Real normb = b.Magnitude();
74 return Standard_False;
76 gp_Vec v = b.Crossed(T);
78 Standard_Real mu = myCos ;
81 //La Normal est portee par la regle
82 Normal.SetLinearForm(Sqrt(1-mu*mu), b, mu, v);
85 // La tangente est perpendiculaire a la normale et a la direction de depouille
86 Tangent = Normal.Crossed(B);
90 BiNormal.Cross(Normal);
95 //=======================================================================
97 //purpose : calculation of trihedron and first derivative
98 //=======================================================================
99 Standard_Boolean GeomFill_DraftTrihedron::D1(const Standard_Real Param,
110 myTrimmed->D2(Param, P, T, aux);
112 Standard_Real normT, normb;
113 normT = T.Magnitude();
115 DT.SetLinearForm(-(T.Dot(aux)), T, aux);
118 gp_Vec db, b = T.Crossed(B);
119 normb = b.Magnitude();
121 return Standard_False;
124 db.SetLinearForm( -(b.Dot(aux)), b, aux);
127 gp_Vec v = b.Crossed(T);
128 gp_Vec dv = db.Crossed(T) + b.Crossed(DT);
130 Standard_Real mu = myCos;
132 Normal.SetLinearForm(Sqrt(1-mu*mu), b, mu, v);
133 DNormal.SetLinearForm(Sqrt(1-mu*mu), db, mu, dv);
135 Tangent = Normal.Crossed(B);
136 normT = Tangent.Magnitude();
138 aux = DNormal.Crossed(B);
139 DTangent.SetLinearForm( -(Tangent.Dot(aux)), Tangent, aux);
143 BiNormal.Cross(Normal);
144 DBiNormal.SetLinearForm(DTangent.Crossed(Normal),Tangent.Crossed(DNormal));
146 return Standard_True;
149 //=======================================================================
151 //purpose : calculation of trihedron and derivatives 1 et 2
152 //=======================================================================
153 Standard_Boolean GeomFill_DraftTrihedron::D2(const Standard_Real Param,
165 gp_Vec T, DT, D2T, aux, aux2;
168 myTrimmed->D3(Param, P, T, aux, aux2);
170 Standard_Real normT, normb;
172 D2T = DDeriv(T, aux, aux2);
173 normT = T.Magnitude();
176 DT.SetLinearForm(-dot, T, aux);
179 gp_Vec db, d2b, b = T.Crossed(B);
180 normb = b.Magnitude();
182 return Standard_False;
184 aux = DT.Crossed(B); aux2 = D2T.Crossed(B);
185 d2b = DDeriv(b, aux, aux2);
188 db.SetLinearForm( -dot, b, aux);
191 gp_Vec v = b.Crossed(T);
192 gp_Vec dv = db.Crossed(T) + b.Crossed(DT);
193 gp_Vec d2v = d2b.Crossed(T) + 2*db.Crossed(DT) + b.Crossed(D2T);
196 Standard_Real mu = myCos, rac;
199 Normal .SetLinearForm( rac, b , mu, v);
200 DNormal .SetLinearForm( rac, db , mu, dv);
201 D2Normal.SetLinearForm( rac, d2b, mu, d2v);
203 Tangent = Normal.Crossed(B);
204 normT = Tangent.Magnitude();
206 aux = DNormal.Crossed(B);
207 aux2 = D2Normal.Crossed(B);
208 D2Tangent = DDeriv(Tangent, aux, aux2);
210 dot = Tangent.Dot(aux);
211 DTangent.SetLinearForm( -dot, Tangent, aux);
215 BiNormal.Cross(Normal);
216 DBiNormal.SetLinearForm(DTangent.Crossed(Normal),Tangent.Crossed(DNormal));
217 D2BiNormal.SetLinearForm(1, D2Tangent.Crossed(Normal),
218 2, DTangent.Crossed(DNormal),
219 Tangent.Crossed(D2Normal));
221 return Standard_True;
225 //=======================================================================
228 //=======================================================================
229 Handle(GeomFill_TrihedronLaw) GeomFill_DraftTrihedron::Copy() const
231 Handle(GeomFill_DraftTrihedron) copy =
232 new (GeomFill_DraftTrihedron) (B,myAngle-PI/2);
233 copy->SetCurve(myCurve);
237 //=======================================================================
238 //function : NbIntervals
240 //=======================================================================
241 Standard_Integer GeomFill_DraftTrihedron::NbIntervals(const GeomAbs_Shape S) const
243 GeomAbs_Shape tmpS=GeomAbs_C0;
245 case GeomAbs_C0: tmpS = GeomAbs_C2; break;
246 case GeomAbs_C1: tmpS = GeomAbs_C3; break;
249 case GeomAbs_CN: tmpS = GeomAbs_CN; break;
250 default: Standard_OutOfRange::Raise();
253 return myCurve->NbIntervals(tmpS);
256 //======================================================================
257 //function :Intervals
259 //=======================================================================
260 void GeomFill_DraftTrihedron::Intervals(TColStd_Array1OfReal& TT,
261 const GeomAbs_Shape S) const
263 GeomAbs_Shape tmpS=GeomAbs_C0;
265 case GeomAbs_C0: tmpS = GeomAbs_C2; break;
266 case GeomAbs_C1: tmpS = GeomAbs_C3; break;
269 case GeomAbs_CN: tmpS = GeomAbs_CN; break;
270 default: Standard_OutOfRange::Raise();
273 myCurve->Intervals(TT, tmpS);
276 //=======================================================================
277 //function : GetAverageLaw
279 //=======================================================================
280 void GeomFill_DraftTrihedron::GetAverageLaw(gp_Vec& ATangent,
284 Standard_Integer Num = 20; //order of digitalization
286 ATangent = gp_Vec(0, 0, 0);
287 ANormal = gp_Vec(0, 0, 0);
288 ABiNormal = gp_Vec(0, 0, 0);
290 Standard_Real Step = (myTrimmed->LastParameter() -
291 myTrimmed->FirstParameter()) / Num;
293 for (Standard_Integer i = 0; i <= Num; i++) {
294 Param = myTrimmed->FirstParameter() + i*Step;
295 if (Param > myTrimmed->LastParameter()) Param = myTrimmed->LastParameter();
303 ABiNormal /= Num + 1;
307 //=======================================================================
308 //function : IsConstant
310 //=======================================================================
311 Standard_Boolean GeomFill_DraftTrihedron::IsConstant() const
313 return (myCurve->GetType() == GeomAbs_Line);
316 //=======================================================================
317 //function : IsOnlyBy3dCurve
319 //=======================================================================
320 Standard_Boolean GeomFill_DraftTrihedron::IsOnlyBy3dCurve() const
322 GeomAbs_CurveType TheType = myCurve->GetType();
328 TheAxe = myCurve->Circle().Axis();
331 case GeomAbs_Ellipse:
333 TheAxe = myCurve->Ellipse().Axis();
336 case GeomAbs_Hyperbola:
338 TheAxe = myCurve->Hyperbola().Axis();
341 case GeomAbs_Parabola:
343 TheAxe = myCurve->Parabola().Axis();
347 { //La normale du plan de la courbe est il perpendiculaire a la BiNormale ?
349 V.SetXYZ(myCurve->Line().Direction().XYZ());
350 return V.IsParallel(B, Precision::Angular());
353 return Standard_False; // pas de risques
356 // La normale du plan de la courbe est il // a la BiNormale ?
358 V.SetXYZ(TheAxe.Direction().XYZ());
359 return V.IsParallel(B, Precision::Angular());