The area

本文介绍了一种通过给定三个交点坐标来计算由抛物线和直线围成的土地面积的方法。利用输入的顶点及两个交点坐标,通过解析几何原理计算出特定区域的面积。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 the vertex of the parabola.


 
Input
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).
 
Output
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.
 
Sample Input
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
 
Sample Output
33.33
40.69

最为基础的计算几何,但是要注意公式千万不要推错了。。。,还有避免一个错误x^3-y^3!=(x-y)^3;

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


struct point{
    double x,y;
}p1,p2,p3;


void solve(){
    double e=(p3.y-p2.y)/(p3.x-p2.x);
    double f=p2.y-p2.x*e;
    double k=p2.x-p1.x;
    k=pow(k,2);
    double a=(p2.y-p1.y)/k;
    double b=-2*a*p1.x;
    double c=a*p1.x*p1.x+p1.y;
    double t=p3.x;
    double s1=(a/3)*t*t*t+(b-e)/2*t*t+(c-f)*t;//注意数学上的合并,x^3-y^3!=(x-y)^3
    t=p2.x;
    double s2=(a/3)*t*t*t+(b-e)/2*t*t+(c-f)*t;
    printf("%.2f\n",s1-s2);
}
int main(){
    int n;
    while(cin>>n){
        while(n-->0){
            cin>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y;
             solve();
        }


    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值