顶点坐标为(b, c)的顶点式抛物线方程式如下
y
=
a
(
x
?
b
)
2
+
c
y=a(x-b)^2+c
y=a(x?b)2+c
此处顶点坐标为
P
1
(
x
1
,
y
1
)
P_1(x_1, y_1)
P1?(x1?,y1?),可得
b
=
x
1
b=x_1
b=x1?,
c
=
y
1
c=y_1
c=y1?.
因此
y
=
a
(
x
?
x
1
)
2
+
y
1
y=a(x-x_1)^2+y_1
y=a(x?x1?)2+y1?
再代入
P
2
(
x
2
,
y
2
)
P_2(x_2, y_2)
P2?(x2?,y2?),得到
a
=
(
y
2
?
y
1
)
(
x
2
?
x
1
)
2
a=\frac {(y_2 - y_1)} {(x_2 - x_1)^2}
a=(x2??x1?)2(y2??y1?)?
k
=
y
3
?
y
2
x
3
?
x
2
k=\frac{y_3 - y_2}{x_3 - x_2}
k=x3??x2?y3??y2??
因此
y
=
k
x
+
d
y=kx+d
y=kx+d
再代入
P
2
(
x
2
,
y
2
)
P_2(x_2, y_2)
P2?(x2?,y2?),得到
d
=
y
2
?
k
x
2
d=y_2 - kx_2
d=y2??kx2?
以
(
a
(
x
?
b
)
2
+
c
?
(
k
x
+
d
)
)
d
x
( a(x-b)^2+c - (kx+d))dx
(a(x?b)2+c?(kx+d))dx为被积表达式,在闭区间
[
x
2
,
x
3
]
[x_2,x_3]
[x2?,x3?]上作定积分,便可得所求阴影部分的面积。
A
=
∫
x
2
x
3
(
a
(
x
?
b
)
2
+
c
?
(
k
x
+
d
)
)
d
x
A=\int_{x_2}^{x_3} ( a(x-b)^2+c - (kx+d))dx
A=∫x2?x3??(a(x?b)2+c?(kx+d))dx
A
=
[
1
3
a
x
3
?
1
2
(
2
a
b
+
k
)
x
2
+
(
a
b
2
+
c
?
d
)
x
]
x
2
x
3
A=\Big[\frac {1} {3} ax^3 - \frac {1} {2} (2ab+k)x^2 + (ab^2+c-d)x\Big]_{x_2} ^{x_3}
A=[31?ax3?21?(2ab+k)x2+(ab2+c?d)x]x2?x3??
代码如下(参考)
#include <iostream>
#include <iomanip>
using namespace std;
double a, b, c, k, d;
// y=a(x-b)^2+c
// y=kx+d
double integral(double x) {
return a*x*x*x/3.0 - (2*a*b+k)*x*x/2.0 + (a*b*b+c-d)*x;
}
int main() {
double x1, y1, x2, y2, x3, y3;
int t;
cin >> t;
for(int i=0; i<t; i++){
cin >> x1 >> y1;
cin >> x2 >> y2;
cin >> x3 >> y3;
b = x1;
c = y1;
a = (y2-y1)/((x2-x1)*(x2-x1));
k = (y3-y2)/(x3-x2);
d = y2-k*x2;
double ans = integral(x3) - integral(x2);
//printf("%.2lf\n", ans);
cout << fixed << setprecision(2) << ans << endl;
}
return 0;
}
测试如下
2
5.00 5.00
0.00 0.00
10.00 0.00
33.33
10.00 10.00
1.00 1.00
14.00 8.222222
40.69