HDU-6535 计算几何 辛普森积分

Problem Description
Chika has just learned about solid geometry! She is very interested in the volume of three-dimensional geometric shapes, so she decides to test you.
Before that, she is going to tell you definitions of the following two three-dimensional geometric shapes.

Oblique circular cone: A cone whose surface is generated by lines joining a fixed point called the apex to the points of a circle, the fixed point lying on a line that is not perpendicular to the circle at its center. (The circular cone is a special kind of oblique circular cone.)
在这里插入图片描述
Pyramid: A polyhedron formed by connecting a polygonal base and a point, called the apex. Each base edge and apex form a triangle, called a lateral face. It is a conic solid with polygonal base. A pyramid with an n-sided base has n+1 vertices, n+1 faces, and 2n edges.
在这里插入图片描述
Chika gives you an oblique circular cone and a pyramid placed in the space rectangular coordinate system. Their bottoms are on the plane z=0. The z-coordinates of their apexes are bigger than 0. Some parts of them may overlap with each other. You need to help Chika to calculate the volume of the union of the two three-dimensional geometric shapes.

Input
The input file contains several lines.
The first line contains three integers x, y, z (z>0), which are the coordinates of the apex of the oblique circular cone.
The second row contains three integers x, y and r (r>0). x and y are the x-coordinate and the y-coordinate of the center of the oblique circular cone’s bottom circle. r is radius of the oblique circular cones’s bottom circle.
The third line contains three integers x, y, z (z>0), which are the coordinates of the apex of the pyramid.
The fourth line contains a positive integer n (n≤1000), which is the number of vertices of the pyramid’s bottom polygon.
Then n lines follow. Each line contains two integers x, y, which are the x-coordinate and y-coordinate of the n vertices of the pyramid’s bottom polygon. Vertex coordinates are given in counterclockwise order. These points do not coincide.
It is guaranteed that the absolute values of all input integers are not greater than 1000.

Output
The output file should contain only one line, including one real number, representing the volume of the union of the oblique circular cone and the pyramid. The relative error or absolute error between your answer and the standard answer should be less than 10−6.

Sample Input
0 0 2
2 0 2
0 0 2
3
2 0
4 -2
4 2

Sample Output
8.9498519738

将立体物体用平面z=h切割,切出圆和多边形
三角剖分求圆与多边形的面积交,S并=S圆+S多边形-S交
面积微元ds按Z轴积分即可
注意两物体,积到顶点及以上部分时就特判面积=0

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxp=1024;
const double inf=1e200;
const double eps=1e-8;
const double pi =acos(-1.0);
int sgn(double x){
   
	if(fabs(x)<eps)return 0;
	return x>0?1:-1;
}
struct Point{
   
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){
   }
	bool operator ==(const Point& b){
   return !sgn(x-b.x)&&!sgn(y-b.y);}
	bool operator  <(const Point& b)const{
   return !sgn(x-b.x)?y<b.y:x<b.x;}
	double operator^(const Point& b){
   return x*b.y-y*b.x;}//叉积
	double operator*(const Point& b){
   return x*b.x+y*b.y;}//点积
	Point operator +(const Point &b){
   return Point(x+b.x,y+b.y);}
	Point operator -(const Point& b){
   return Point(x-b.x,y-b.y);}
	Point operator *(const double &k){
   return Point(x*k,y*k);}
	Point operator /(const double &k){
   return Point(x/k,y/k);}
	double len(){
   return hypot(x,y);}
	double len2(){
   return x*x+y*y;}
	double rad
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值