1 -- Created on: 1995-08-28
2 -- Created by: Laurent BOURESCHE
3 -- Copyright (c) 1995-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.
21 -- Modified: 28/02/1996 by PMN : HermiteCoefficients added
22 -- Modified: 19/02/1997 by JCT : EvalPoly2Var added
24 -- Modified: 05/09/97 by JPI for SSV : JacobiPolynomial --
25 -- DoubleJacobiPolynomial, HermiteInterpolate, JacobiParameters
30 ---Purpose: PLib means Polynomial functions library. This pk
31 -- provides basic computation functions for
32 -- polynomial functions.
35 uses Standard, math, TColStd, gp, TColgp, GeomAbs
38 deferred class Base from PLib;
39 class JacobiPolynomial from PLib;
40 class HermitJacobi from PLib;
41 class DoubleJacobiPolynomial from PLib;
43 NoWeights returns Array1OfReal from TColStd;
44 ---Purpose: Used as argument for a non rational functions
49 NoWeights2 returns Array2OfReal from TColStd;
50 ---Purpose: Used as argument for a non rational functions
55 SetPoles(Poles : Array1OfPnt from TColgp;
56 FP : out Array1OfReal from TColStd);
57 ---Purpose: Copy in FP the coordinates of the poles.
59 SetPoles(Poles : Array1OfPnt from TColgp;
60 Weights : Array1OfReal from TColStd;
61 FP : out Array1OfReal from TColStd);
62 ---Purpose: Copy in FP the coordinates of the poles.
64 GetPoles(FP : Array1OfReal from TColStd;
65 Poles : out Array1OfPnt from TColgp);
66 ---Purpose: Get from FP the coordinates of the poles.
68 GetPoles(FP : Array1OfReal from TColStd;
69 Poles : out Array1OfPnt from TColgp;
70 Weights : out Array1OfReal from TColStd);
71 ---Purpose: Get from FP the coordinates of the poles.
73 SetPoles(Poles : Array1OfPnt2d from TColgp;
74 FP : out Array1OfReal from TColStd);
75 ---Purpose: Copy in FP the coordinates of the poles.
77 SetPoles(Poles : Array1OfPnt2d from TColgp;
78 Weights : Array1OfReal from TColStd;
79 FP : out Array1OfReal from TColStd);
80 ---Purpose: Copy in FP the coordinates of the poles.
82 GetPoles(FP : Array1OfReal from TColStd;
83 Poles : out Array1OfPnt2d from TColgp);
84 ---Purpose: Get from FP the coordinates of the poles.
86 GetPoles(FP : Array1OfReal from TColStd;
87 Poles : out Array1OfPnt2d from TColgp;
88 Weights : out Array1OfReal from TColStd);
89 ---Purpose: Get from FP the coordinates of the poles.
91 Bin(N,P : Integer) returns Real;
92 ---Purpose: Returns the Binomial Cnp. N should be <= BSplCLib::MaxDegree().
94 RationalDerivative(Degree : Integer;
99 All : Boolean = Standard_True);
100 ---Purpose: Computes the derivatives of a ratio at order
101 -- <N> in dimension <Dimension>.
103 -- <Ders> is an array containing the values of the
104 -- input derivatives from 0 to Min(<N>,<Degree>).
105 -- For orders higher than <Degree> the inputcd /s2d1/BMDL/
106 -- derivatives are assumed to be 0.
108 -- Content of <Ders> :
110 -- x(1),x(2),...,x(Dimension),w
111 -- x'(1),x'(2),...,x'(Dimension),w'
112 -- x''(1),x''(2),...,x''(Dimension),w''
114 -- If <All> is false, only the derivative at order
115 -- <N> is computed. <RDers> is an array of length
116 -- Dimension which will contain the result :
118 -- x(1)/w , x(2)/w , ... derivated <N> times
120 -- If <All> is true all the derivatives up to order
121 -- <N> are computed. <RDers> is an array of length
122 -- Dimension * (N+1) which will contains :
124 -- x(1)/w , x(2)/w , ...
125 -- x(1)/w , x(2)/w , ... derivated <1> times
126 -- x(1)/w , x(2)/w , ... derivated <2> times
128 -- x(1)/w , x(2)/w , ... derivated <N> times
130 -- Warning: <RDers> must be dimensionned properly.
133 RationalDerivatives(DerivativesRequest : Integer;
135 PolesDerivatives : in out Real;
136 WeightsDerivatives : in out Real;
137 RationalDerivates : in out Real) ;
139 ---Purpose: Computes DerivativesRequest derivatives of a ratio at
140 -- of a BSpline function of degree <Degree>
141 -- dimension <Dimension>.
143 -- <PolesDerivatives> is an array containing the values
144 -- of the input derivatives from 0 to <DerivativeRequest>
145 -- For orders higher than <Degree> the input
146 -- derivatives are assumed to be 0.
148 -- Content of <PoleasDerivatives> :
150 -- x(1),x(2),...,x(Dimension)
151 -- x'(1),x'(2),...,x'(Dimension)
152 -- x''(1),x''(2),...,x''(Dimension)
155 -- WeightsDerivatives is an array that contains derivatives
156 -- from 0 to <DerivativeRequest>
157 -- After returning from the routine the array
158 -- RationalDerivatives contains the following
159 -- x(1)/w , x(2)/w , ...
160 -- x(1)/w , x(2)/w , ... derivated once
161 -- x(1)/w , x(2)/w , ... twice
162 -- x(1)/w , x(2)/w , ... derivated <DerivativeRequest> times
164 -- The array RationalDerivatives and PolesDerivatives
165 -- can be same since the overwrite is non destructive within
168 -- Warning: <RationalDerivates> must be dimensionned properly.
171 EvalPolynomial(U : Real;
172 DerivativeOrder : Integer ;
174 Dimension : Integer ;
175 PolynomialCoeff : in out Real ;
176 Results : in out Real) ;
178 ---Purpose: Performs Horner method with synthethic division
180 -- parameter <U>, with <Degree> and <Dimension>.
181 -- PolynomialCoeff are stored in the following fashion
182 -- c0(1) c0(2) .... c0(Dimension)
183 -- c1(1) c1(2) .... c1(Dimension)
186 -- cDegree(1) cDegree(2) .... cDegree(Dimension)
187 -- where the polynomial is defined as :
190 -- c0 + c1 X + c2 X + .... cDegree X
192 -- Results stores the result in the following format
194 -- f(1) f(2) .... f(Dimension)
196 -- f (1) f (2) .... f (Dimension)
198 -- (DerivativeRequest) (DerivativeRequest)
199 -- f (1) f (Dimension)
201 -- this just evaluates the point at parameter U
203 -- Warning: <Results> and <PolynomialCoeff> must be dimensioned properly
207 NoDerivativeEvalPolynomial(U : Real;
209 Dimension : Integer ;
210 DegreeDimension : Integer ;
211 PolynomialCoeff : in out Real ;
212 Results : in out Real) ;
213 ---Purpose: Same as above with DerivativeOrder = 0;
215 EvalPoly2Var(U,V : Real;
216 UDerivativeOrder,VDerivativeOrder : Integer ;
217 UDegree,VDegree,Dimension : Integer ;
218 PolynomialCoeff : in out Real;
219 Results : in out Real) ;
221 ---Purpose: Applies EvalPolynomial twice to evaluate the derivative
222 -- of orders UDerivativeOrder in U, VDerivativeOrder in V
226 -- PolynomialCoeff are stored in the following fashion
227 -- c00(1) .... c00(Dimension)
228 -- c10(1) .... c10(Dimension)
230 -- cm0(1) .... cm0(Dimension)
232 -- c01(1) .... c01(Dimension)
233 -- c11(1) .... c11(Dimension)
235 -- cm1(1) .... cm1(Dimension)
237 -- c0n(1) .... c0n(Dimension)
238 -- c1n(1) .... c1n(Dimension)
240 -- cmn(1) .... cmn(Dimension)
243 -- where the polynomial is defined as :
245 -- c00 + c10 U + c20 U + .... + cm0 U
247 -- + c01 V + c11 UV + c21 U V + .... + cm1 U V
249 -- + .... + c0n V + .... + cmn U V
251 -- with m = UDegree and n = VDegree
253 -- Results stores the result in the following format
255 -- f(1) f(2) .... f(Dimension)
257 -- Warning: <Results> and <PolynomialCoeff> must be dimensioned properly
262 EvalLagrange(U : Real ;
263 DerivativeOrder : Integer ;
265 Dimension : Integer ;
266 ValueArray : in out Real;
267 ParameterArray : in out Real;
268 Results : in out Real) returns Integer ;
270 ---Purpose: Performs the Lagrange Interpolation of
271 -- given series of points with given parameters
272 -- with the requested derivative order
273 -- Results will store things in the following format
274 -- with d = DerivativeOrder
276 -- [0], [Dimension-1] : value
277 -- [Dimension], [Dimension + Dimension-1] : first derivative
279 -- [d *Dimension], [d*Dimension + Dimension-1]: dth derivative
281 EvalCubicHermite(U : Real ;
282 DerivativeOrder : Integer ;
283 Dimension : Integer ;
284 ValueArray : in out Real;
285 DerivativeArray : in out Real;
286 ParameterArray : in out Real;
287 Results : in out Real) returns Integer ;
289 ---Purpose: Performs the Cubic Hermite Interpolation of
290 -- given series of points with given parameters
291 -- with the requested derivative order.
292 -- ValueArray stores the value at the first and
293 -- last parameter. It has the following format :
294 -- [0], [Dimension-1] : value at first param
295 -- [Dimension], [Dimension + Dimension-1] : value at last param
296 -- Derivative array stores the value of the derivatives
297 -- at the first parameter and at the last parameter
298 -- in the following format
299 -- [0], [Dimension-1] : derivative at
301 -- [Dimension], [Dimension + Dimension-1] : derivative at
304 -- ParameterArray stores the first and last parameter
305 -- in the following format :
306 -- [0] : first parameter
307 -- [1] : last parameter
309 -- Results will store things in the following format
310 -- with d = DerivativeOrder
312 -- [0], [Dimension-1] : value
313 -- [Dimension], [Dimension + Dimension-1] : first derivative
315 -- [d *Dimension], [d*Dimension + Dimension-1]: dth derivative
317 HermiteCoefficients(FirstParameter : in Real;
318 LastParameter : in Real;
319 FirstOrder : in Integer;
320 LastOrder : in Integer;
321 MatrixCoefs : in out Matrix from math)
323 ---Purpose: This build the coefficient of Hermite's polynomes on
324 -- [FirstParameter, LastParameter]
326 -- if j <= FirstOrder+1 then
328 -- MatrixCoefs[i, j] = ith coefficient of the polynome H0,j-1
332 -- MatrixCoefs[i, j] = ith coefficient of the polynome H1,k
333 -- with k = j - FirstOrder - 2
336 -- - |FirstParameter| > 100
337 -- - |LastParameter| > 100
338 -- - |FirstParameter| +|LastParameter| < 1/100
339 -- - |LastParameter - FirstParameter|
340 -- / (|FirstParameter| +|LastParameter|) < 1/100
343 ----------------------------------------------------------------
344 -- The following functions computes poles corresponding to --
345 -- given coefficients. --
346 -- PLib::NoWeights() must be given for non rational functions--
347 ----------------------------------------------------------------
349 CoefficientsPoles(Coefs : in Array1OfPnt from TColgp;
350 WCoefs : in Array1OfReal from TColStd;
351 Poles : in out Array1OfPnt from TColgp;
352 WPoles : in out Array1OfReal from TColStd);
354 CoefficientsPoles(Coefs : in Array1OfPnt2d from TColgp;
355 WCoefs : in Array1OfReal from TColStd;
356 Poles : in out Array1OfPnt2d from TColgp;
357 WPoles : in out Array1OfReal from TColStd);
359 CoefficientsPoles(Coefs : in Array1OfReal from TColStd;
360 WCoefs : in Array1OfReal from TColStd;
361 Poles : in out Array1OfReal from TColStd;
362 WPoles : in out Array1OfReal from TColStd);
364 CoefficientsPoles(dim : in Integer from Standard;
365 Coefs : in Array1OfReal from TColStd;
366 WCoefs : in Array1OfReal from TColStd;
367 Poles : in out Array1OfReal from TColStd;
368 WPoles : in out Array1OfReal from TColStd);
371 ----------------------------------------------------------------
372 -- The following functions trim the Bezier curve between two --
373 -- parametric values U1, U2. --
374 -- Can be used to extend the curve : --
375 -- Parameters U1<0. or U2>1. can be given. --
376 -- PLib::NoWeights() must be given for non rational functions--
377 ----------------------------------------------------------------
380 Trimming (U1, U2 : in Real;
381 Coeffs : in out Array1OfPnt from TColgp;
382 WCoeffs : in out Array1OfReal from TColStd);
385 Trimming (U1, U2 : in Real;
386 Coeffs : in out Array1OfPnt2d from TColgp;
387 WCoeffs : in out Array1OfReal from TColStd);
390 Trimming (U1, U2 : in Real;
391 Coeffs : in out Array1OfReal from TColStd;
392 WCoeffs : in out Array1OfReal from TColStd);
395 Trimming (U1, U2 : in Real;
397 Coeffs : in out Array1OfReal from TColStd;
398 WCoeffs : in out Array1OfReal from TColStd);
403 ----------------------------------------------------------------
404 -- The following functions computes poles corresponding to --
405 -- given coefficients. --
406 -- PLib::NoWeights2() must be given for non rational --
408 ----------------------------------------------------------------
410 CoefficientsPoles(Coefs : in Array2OfPnt from TColgp;
411 WCoefs : in Array2OfReal from TColStd;
412 Poles : in out Array2OfPnt from TColgp;
413 WPoles : in out Array2OfReal from TColStd);
416 ----------------------------------------------------------------
417 -- The following functions trim the Bezier surface between --
418 -- two parametric values. --
419 -- Can be used to extend the surface : --
420 -- Parameters U1(V1)<0. or U2(V2)>1. can be given. --
421 -- PLib::NoWeights2() must be given for non rational --
423 ----------------------------------------------------------------
426 UTrimming (U1, U2 : in Real;
427 Coeffs : in out Array2OfPnt from TColgp;
428 WCoeffs : in out Array2OfReal from TColStd);
431 VTrimming (V1, V2 : in Real;
432 Coeffs : in out Array2OfPnt from TColgp;
433 WCoeffs : in out Array2OfReal from TColStd);
436 HermiteInterpolate(Dimension : in Integer;
437 FirstParameter,LastParameter : in Real;
438 FirstOrder,LastOrder : in Integer;
439 FirstConstr,LastConstr : Array2OfReal from TColStd;
440 Coefficients : out Array1OfReal from TColStd)
441 returns Boolean from Standard;
442 ---Purpose : Compute the coefficients in the canonical base of the
443 -- polynomial satisfying the given constraints
444 -- at the given parameters
445 -- The array FirstContr(i,j) i=1,Dimension j=0,FirstOrder
446 -- contains the values of the constraint at parameter FirstParameter
447 -- idem for LastConstr
449 JacobiParameters (ConstraintOrder: Shape from GeomAbs;
450 MaxDegree, Code: in Integer;
451 NbGaussPoints: out Integer;
452 WorkDegree: out Integer)
453 ---Purpose : Compute the number of points used for integral
454 -- computations (NbGaussPoints) and the degree of Jacobi
455 -- Polynomial (WorkDegree).
456 -- ConstraintOrder has to be GeomAbs_C0, GeomAbs_C1 or GeomAbs_C2
457 -- Code: Code d' init. des parametres de discretisation.
463 -- = 1 calcul rapide avec precision moyenne.
464 -- = 2 calcul rapide avec meilleure precision.
465 -- = 3 calcul un peu plus lent avec bonne precision.
466 -- = 4 calcul lent avec la meilleure precision possible.
468 raises ConstructionError from Standard;
469 -- if ConstraintOrder or Code is not valid
470 -- MaxDegree < 2*NivConstr+2 or MaxDegree > 50
473 NivConstr(ConstraintOrder : Shape from GeomAbs)
474 ---Purpose: translates from GeomAbs_Shape to Integer
476 raises ConstructionError from Standard;
478 ConstraintOrder(NivConstr : Integer)
479 ---Purpose: translates from Integer to GeomAbs_Shape
480 returns Shape from GeomAbs
481 raises ConstructionError from Standard;
484 EvalLength(Degree : Integer;
486 PolynomialCoeff : in out Real;
490 EvalLength(Degree : Integer;
492 PolynomialCoeff : in out Real;