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

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;
}

 

转载于:https://www.cnblogs.com/lavender913/p/3310891.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值