aoj1313(*simpson公式求三维体积)
2017-03-01 21:57
471 查看
/* translation: 三维坐标系上有2个棱柱,分别平行与Z轴以及Y轴,现在分别给出它们在XY平面和XZ平面上的底面顶点,求两个棱柱相交部分的体积。 solution: 主要思路是不难,但前提得知道simpson公式。利用该公式即可将积分公式化为普通的公式。然后微积分求出来的既是体积。 */ #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int maxn = 200 + 5; const double INF = 0x3f3f3f3f * 1.0; int X1[maxn], Y1[maxn], m, n; int X2[maxn], Z2[maxn]; vector<int> xv; double getWidth(int* X, int* Y, int n, double x) { double lb = INF, ub = -INF; for(int i = 0; i < n; i++) { double ax = X[i], ay = Y[i]; double bx = X[(i+1)%n], by = Y[(i+1)%n]; if((ax - x) * (bx - x) <= 0 && ax != bx) { double y = (by - ay) / (bx - ax) * (x - ax) + ay; lb = min(lb, y); ub = max(ub, y); } } return max(0.0, ub-lb); } int main() { //freopen("in.txt", "r", stdin); while(~scanf("%d%d", &m, &n)) { if(m + n == 0) break; for(int i = 0; i < m; i++) scanf("%d%d", &X1[i], &Y1[i]); for(int i = 0; i < n; i++) scanf("%d%d", &X2[i], &Z2[i]); xv.clear(); for(int i = 0; i < m; i++) xv.push_back(X1[i]); for(int i = 0; i < n; i++) xv.push_back(X2[i]); int min1 = *min_element(X1, X1 + m), max1 = *max_element(X1, X1 + m); int min2 = *min_element(X2, X2 + n), max2 = *max_element(X2, X2 + n); sort(xv.begin(), xv.end()); double ans = 0; for(int i = 0; i < xv.size()-1; i++) { double a = xv[i], b = xv[i+1], c = (a + b) / 2; if(c >= min1 && c <= max1 && c >= min2 && c <= max2) { double fa = getWidth(X1, Y1, m, a) * getWidth(X2, Z2, n, a); double fb = getWidth(X1, Y1, m, b) * getWidth(X2, Z2, n, b); double fc = getWidth(X1, Y1, m, c) * getWidth(X2, Z2, n, c); ans += (b - a) / 6 * (fa + 4 * fc + fb); } } printf("%.10f\n", ans); } return 0; }
相关文章推荐
- 利用欧拉四面体公式求任意三棱锥的体积
- [再寄小读者之数学篇](2014-06-19 三维插值公式)
- 【欧拉体积公式及行列式】AC总在数十WA后——POJ 2208
- Hdu 1411 校庆神秘建筑(欧拉四面体体积公式)
- 定义函数areaZ,功能是求圆锥体积。在主函数中输入半径r和高h,调用函数areaZ求体积,并在主函数中输出圆锥的体积,其中变量r,h均为double型数据。(公式v=h*3.14*r2/3)。
- HDU3662(求三维凸包表面的多边形个数,表面三角形个数,体积,表面积,凸包重心,凸包中点到面的距离)
- 行列式 与 n维平行多面体体积 公式的证明 determinant volume proof
- SAT数学常用公式之面积和体积
- 球的体积微分公式
- acmore|acmore.cc1006编写程序,显示计算的结果1007可以使用以下公式计算1008转换温度1009计算圆柱体的体积1010将英尺转换为米
- vrn:基于直接体积回归的单幅图像大姿态三维人脸重建
- 三维凸包模版 求三维凸包的表面积和体积
- 圆台体积公式的推导
- vrn:基于直接体积回归的单幅图像大姿态三维人脸重建
- 三维坐标绕轴坐标旋转公式
- 三维圆环计算公式
- 定义函数areaZ,功能是求圆锥体积。在主函数中输入半径r和高h,调用函数areaZ求体积,并在主函数中输出圆锥体积,其中变量r,h均为double型数据。(公式:v=h*3.14*r2/3)
- MT【89】三棱锥的体积公式
- 关于圆锥的体积公式
- 二维,三维坐标旋转算法(公式)