根据点 p1 y = a(x- x1 )^2 + c 在根据一个点 求出 a ,c。 根据 p2 p3 求出直线。
直接simpson 。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALLL(x) x.begin(),x.end()
#define SORT(x) sort(ALLL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILLL(x,c) memset(x,c,sizeof(x))
using namespace std;
const double eps = 1e-9;
#define LL long long
#define pb push_back
double a,b,c , k ;
bool bo = 1;
double F(double x){
if(bo ==1)
return a*(x-b)*(x-b)+c;
else
return k*x +c;
}
// 三点simpson法。这里要求F是一个全局函数
double simpson(double a,double b){
double c = a+(b-a)/2;
return (F(a) + 4*F(c) + F(b))*(b-a)/6;
}
// 自适应Simpson公式(递归过程)。已知整个区间[a,b]上的三点simpson值A
double asr(double a , double b ,double eps ,double A){
double c = a+ (b-a)/2;
double L = simpson(a,c) ,R = simpson(c,b);
if(fabs(A-L-R)<=15*eps) return L + R +(A-L-R)/15;
return asr(a,c,eps/2,L) + asr(c,b,eps/2,R);
}
// 自适应Simpson公式(主过程)
double asr(double a, double b, double eps) {
return asr(a, b, eps, simpson(a, b));
}
double x[3],y[3];
void solve(){
b= x[0];
c = y[0];
a = (y[1] - c) / ((x[1] - b) * (x[1] - b));
bo = 1;
double ans = asr(x[1],x[2],1e-4);
k = (y[2] - y[1])/(x[2] - x[1]);
c = y[1] - k*x[1];
bo = 0 ;
double ans2 = asr(x[1],x[2],1e-4);
ans -= ans2;
printf("%.2f\n",ans);
}
int main(){
int t;
cin >>t ;
while(t--){
for(int i=0;i<=2;i++){
scanf("%lf%lf",&x[i],&y[i]);
}
solve();
}
return 0;
}