您的位置:首页 > 其它

The area(抛物线与直线的相交面积)

2013-09-09 21:11 309 查看

The area

时间限制(普通/Java):3000MS/10000MS 运行内存限制:65536KByte

描述

Ignatius bought a land last week, but he didn't know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land?
Note: The point P1 in the picture is a random point on the parabola, and P2, P3 are the intersectant points. Any two points of P1, P2 and P3 are not coincidence each other.



输入

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).

输出

For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.

样例输入

2
5.000000 5.000000
0.000000 0.000000
10.000000 0.000000
10.000000 10.000000
1.000000 1.000000
14.000000 8.222222

样例输出

33.33
40.69

题目大意:给出抛物线顶掉p1的坐标及与直线的交点p2和p3的坐标,求相交部分的面积。
题解:抛物线面积:顶点为(x1,y1),方程为y=a(x-x1)^2+y1 ---->a=(y2-y1)/((x2-x1)*(x2-x1))

   直线p2,p3的方程设为y=kx+b;-->k=(y3-y2)/(x3-x2);

   又p2点在直线上,所以y2=k*x2+b,--->b=y2-k*x2;

   然后微分,区间为(x2,x3),方程化简可得以下式子。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
int t;
double x1,y1,x2,y2,x3,y3;
cin>>t;
while(t--)
{
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
double a=(y2-y1)/((x2-x1)*(x2-x1));
double k=(y3-y2)/(x3-x2);
double b=y2-k*x2;
double c=x3-x2;
double d=x3*x3-x2*x2;
double ans;
ans=a*(x3*x3*x3-x2*x2*x2)/3-a*x1*d+a*x1*x1*c+y1*c-k*d/2-b*c;
printf("%.2lf\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: