数学积分—— The area(求阴影部分的面积)

本文介绍了一种通过解析几何和积分运算求解由抛物线和直线围成的阴影区域面积的方法。通过给出的三个交点坐标,利用二次方程和直线方程,计算出面积。注意使用double类型以确保精度。

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

题意描述:
就是求阴影部分的面积,一个公式解决问题(经过推算),实际上也就是积分的加减运算。
注意点:
题目上说用float,结果float过不了,结果还是double解决了问题
原文:
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
Hint
For float may be not accurate enough, please use double instead of float.
AC代码:

#include<stdio.h>
int main()
{
	int t;
	double a,b,c,x1,x2,x3,y1,y2,y3,k,w,s;
	scanf("%d", &t);
	while(t--)
	{
		s=0;
	scanf("%lf %lf", &x1,&y1);
	scanf("%lf %lf", &x2,&y2);
	scanf("%lf %lf", &x3,&y3);
	a=((y1-y2)/(x1-x2)-(y2-y3)/(x2-x3))/((x1+x2)-(x2+x3));
	b=(y1-y2)/(x1-x2)-a*(x1+x2);
	c=y1-a*x1*x1-b*x1;
	k=(y3-y2)/(x3-x2);
	w=y3-k*x3;
	s=(1.0*1/3)*a*(x3*x3*x3-x2*x2*x2)+(1.0*1/2)*b*(x3*x3-x2*x2)+c*(x3-x2)-(1.0*1/2)*k*(x3*x3-x2*x2)-w*(x3-x2);
	printf("%.2lf\n", s);
	}
	return 0; 
 } 
在C++中计算图形的阴影部分面积通常涉及到几何形状和算法,特别是当涉及到复杂的图形或需要用户输入的情况。例如,如果你想要计算一个圆形或矩形内部阴影区域的面积,你可以考虑以下几个步骤: 1. **基本形状**: - 圆形:假设有一个圆形,阴影部分可能是圆的一部分,你需要确定阴影落在圆内的部分。这可以通过阴影区域半径并与整个圆的半径做比较来实现。 - 矩形:如果阴影是一个矩形,你需要判断它是否完全覆盖或部分覆盖原图形,然后计算两者重叠部分面积。 2. **函数声明**: - 使用`double`或`float`作为返回类型,因为面积通常是数值型的。 - 如果需要用户输入,可以创建函数接收形状的参数,如圆的半径或矩形的长宽。 3. **算法**: - 对于圆形,可以计算出阴影部分面积是圆面积减去两个同心圆(一个是原圆,另一个是阴影边界)面积的差。 - 对于矩形,可以使用`std::min`函数找到矩形和阴影部分的最大交集边长,然后计算这个交集的面积。 4. **代码示例**: ```cpp #include <cmath> #include <iostream> double circleShadowArea(double radius, double shadowRadius) { return M_PI * pow(radius, 2) - M_PI * pow(shadowRadius, 2); } double rectangleShadowArea(double width, double height, double shadowWidth, double shadowHeight) { double intersection = std::min(width, shadowWidth); return intersection * std::min(height, shadowHeight); } int main() { // 示例:计算圆形和矩形的阴影面积 double circleRad = 5.0; double shadowRad = 3.0; double rectWidth = 10.0; double rectHeight = 8.0; double rectShadowW = 6.0; double rectShadowH = 4.0; double circleArea = circleShadowArea(circleRad, shadowRad); double rectArea = rectangleShadowArea(rectWidth, rectHeight, rectShadowW, rectShadowH); std::cout << "Circle Shadow Area: " << circleArea << std::endl; std::cout << "Rectangle Shadow Area: " << rectArea << std::endl; return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

皮皮皮皮皮皮皮卡乒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值