Graphics Reference
In-Depth Information
B.8.1
Function integration for arc length computation
Given a function
f
(
x
), Gaussian quadrature can be used to produce an arbitrarily close approximation to
the integral of the function between two values,
R
a
f ðxÞ
Gaussian quadrature approximates the integral as a sum of weighted evaluations of the function at spe-
cific values (abscissas). The number of evaluations controls the error in the approximation. In its general
form, Gaussian quadrature incorporates a multiplicative function,
W
(
x
), which can condition some func-
tions for the approximation (
Eq. B.148
). Gauss-Legendre integration is a special case in which
W
(
x
)
¼
1.0, and it results in
Equation B.149
. The code in
Figure B.55
for
n ¼
10 duplicates that used in
Chapter 3
,
Section 2.1
for computing arc length.
Figure B.56
gives the code for computing Gauss-Legendre weights
and abscissas for arbitrary
n.
Z
b
X
n
i¼
1
w
i
f ðx
i
Þ
ðWðxÞf ðxÞÞdx
(B.148)
a
Z
b
X
n
i¼
1
wf ðx
i
Þ
f ðxÞdx
(B.149)
a
/* -------------------------------------------------------------------
INTEGRATE FUNCTION
use gaussian quadrature to integrate square root of given function in
the given interval */
double integrate_func(polynomial_td *func,interval_td *interval)
{
double x[5]={.1488743389,.4333953941,.6794095682,.8650633666,.9739065285};
double w[5]={.2966242247,.2692667193,.2190863625,.1494513491,.0666713443};
double length, midu, dx, diff;
int i;
double evaluate_polynomial();
double u1,u2;
u1 = interval->u1;
u2 = interval->u2;
midu = (u1+u2)/2.0;
diff = (u2-u1)/2.0;
length = 0.0;
for (i=0; i<5; i++) {
dx = diff*x[i];
length += w[i]*(sqrt(evaluate_polynomial(func,midu+dx)) +
sqrt(evaluate_polynomial(func,midu-dx)));
}
length *= diff;
return (length);
}
FIGURE B.55
Search WWH ::
Custom Search