UVA 11769 All Souls Night 的三维凸包要求的表面面积
主题链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=2869">点击打开链接
求给定的3维坐标的凸包的表面积
三维凸包裸题。。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define PR 1e-8
#define N 510
struct TPoint{
double x, y, z;
TPoint(){}
TPoint(double _x, double _y, double _z):x(_x), y(_y), z(_z){}
TPoint operator-(const TPoint p){return TPoint(x-p.x, y-p.y, z-p.z);}
TPoint operator*(const TPoint p){return TPoint(y*p.z-z*p.y, z*p.x-x*p.z, x*p.y-y*p.x);}
double operator^(const TPoint p){return x*p.x+y*p.y+z*p.z;}
};
struct fac{
int a, b, c;
bool ok;
};
struct T3dhull{
int n;
TPoint ply[N];
int trianglecnt;
fac tri[N];
int vis[N][N];
double dist(TPoint a){return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);}
double area(TPoint a, TPoint b, TPoint c)
{ return dist((b-a)*(c-a));}
double volume(TPoint a, TPoint b, TPoint c, TPoint d)
{ return (b-a)*(c-a)^(d-a);}
double ptoplane(TPoint &p, fac &f)
{
TPoint m = ply[f.b] - ply[f.a], n = ply[f.c]-ply[f.a], t = p-ply[f.a];
return (m*n)^t;
}
void deal(int p, int a, int b){
int f = vis[a][b];
fac add;
if(tri[f].ok)
{
if((ptoplane(ply[p], tri[f])) > PR)
dfs(p, f);
else
{
add.a = b, add.b = a, add.c = p, add.ok = 1;
vis[p][b] = vis[a][p] = vis[b][a] = trianglecnt;
tri[trianglecnt++] = add;
}
}
}
void dfs(int p, int cnt) {
tri[cnt].ok = 0;
deal(p, tri[cnt].b, tri[cnt].a);
deal(p, tri[cnt].c, tri[cnt].b);
deal(p, tri[cnt].a, tri[cnt].c);
}
bool same(int s, int e) {
TPoint a = ply[tri[s].a], b = ply[tri[s].b], c = ply[tri[s].c];
return fabs(volume(a,b,c,ply[tri[e].a])) < PR
&& fabs(volume(a,b,c,ply[tri[e].b])) < PR
&& fabs(volume(a,b,c,ply[tri[e].c])) < PR;
}
void construct()
{
int i, j;
trianglecnt = 0;
if(n<4) return ;
bool tmp = true;
for(i = 1; i < n; i++)
{
if((dist(ply[0]-ply[i])) > PR)
{
swap(ply[1], ply[i]);
tmp = false;
break;
}
}
if(tmp)return ;
tmp = true;
for(i = 2; i < n; i++)
{
if((dist((ply[0]-ply[1])*(ply[1]-ply[i]))) > PR)
{
swap(ply[2], ply[i]);
tmp = false;
break;
}
}
if(tmp) return ;
tmp = true;
for(i = 3; i < n; i++)
{
if(fabs((ply[0]-ply[1])*(ply[1]-ply[2])^(ply[0]-ply[i]))>PR)
{
swap(ply[3], ply[i]);
tmp =false;
break;
}
}
if(tmp)return ;
fac add;
for(i = 0; i < 4; i++)
{
add.a = (i+1)%4, add.b = (i+2)%4, add.c = (i+3)%4, add.ok = 1;
if((ptoplane(ply[i], add))>0)
swap(add.b, add.c);
vis[add.a][add.b] = vis[add.b][add.c] = vis[add.c][add.a] = trianglecnt;
tri[trianglecnt++] = add;
}
for(i = 4; i < n; i++)
{
for(j = 0; j < trianglecnt; j++)
{
if(tri[j].ok && (ptoplane(ply[i], tri[j])) > PR)
{
dfs(i, j); break;
}
}
}
int cnt = trianglecnt;
trianglecnt = 0;
for(i = 0; i < cnt; i++)
{
if(tri[i].ok)
tri[trianglecnt++] = tri[i];
}
}
double area()
{
double ret = 0;
for(int i = 0; i < trianglecnt; i++)
ret += area(ply[tri[i].a], ply[tri[i].b], ply[tri[i].c]);
return ret/2.0;
}
double volume()
{
TPoint p(0,0,0);
double ret = 0;
for(int i = 0; i < trianglecnt; i++)
ret += volume(p, ply[tri[i].a], ply[tri[i].b], ply[tri[i].c]);
return fabs(ret/6);
}
}hull; int main(){
int Cas = 1;
while(scanf("%d",&hull.n), hull.n){
int i ;
for(i = 0; i < hull.n; i++)
scanf("%lf %lf %lf",&hull.ply[i].x, &hull.ply[i].y, &hull.ply[i].z);
hull.construct();
printf("Case %d: %.2lf\n", Cas++, hull.area());
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
UVA 11769 All Souls Night 的三维凸包要求的表面面积的更多相关文章
- POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心
题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...
- hdu4273Rescue(三维凸包重心)
链接 模板题已不叫题.. 三维凸包+凸包重心+点到平面距离(体积/点积) 体积-->混合积(先点乘再叉乘) #include <iostream> #include<cstd ...
- hdu4449Building Design(三维凸包+平面旋转)
链接 看了几小时也没看懂代码表示的何意..无奈下来问问考研舍友. 还是考研舍友比较靠谱,分分钟解决了我的疑问. 可能三维的东西在纸面上真的不好表示,网上没有形象的题解,只有简单"明了&quo ...
- hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...
- HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...
- bzoj 1209: [HNOI2004]最佳包裹 三维凸包
1209: [HNOI2004]最佳包裹 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 160 Solved: 58[Submit][Status] ...
- bzoj 1964: hull 三维凸包 计算几何
1964: hull 三维凸包 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 54 Solved: 39[Submit][Status][Discuss ...
- POJ 3528 求三维凸包表面积
也是用模板直接套的题目诶 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include < ...
- BZOJ1209 [HNOI2004]最佳包裹 三维凸包 计算几何
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1209 题目概括 给出立体的n个点.求三维凸包面积. 题解 增量法,看了一天,还是没有完全懂. 上板 ...
随机推荐
- 在Windows通过使用MinGW静态编译Assimp
使用MinGW静态编译Assimp 到了5月份了.没有写一篇日志,于是自己从知识库里面拿出一篇文章充数吧.这次将要解说怎样在Windows下使用MinGW静态编译Assimp. Assimp是眼下比較 ...
- 【iOS开发】 常遇到的Crash和Bug处理
一,Unknown type name .... 如果是报这个错误,多半是你的对象类型没有被识别,检查是不是没有引用对应的库或者头文件在你的文件头部分,还有可能是循环引用导致的,循环引用的解决方法就是 ...
- 百度富文本编辑器UEditor1.3上传图片附件等
今天一直在整我的一个项目的编辑器上传图片,我用的是百度UEditor 1.3版本号的:如今已经有了1.4的了,只是还算比較新吧,可是官网上面没有上传图片这些的教程,而网上对于这方面的资料非常少啊,折腾 ...
- JarSearch
个人做的小工具分享给大家~~. 支持从压缩文件搜索文件,特别是根据部分类文件名在jar里查找文件,比较方便,效率也还不错. 也支持从目录查找 http://pan.baidu.com/s/1feYaM ...
- Windows Phone开发(45):推送通知大结局——Raw通知
原文:Windows Phone开发(45):推送通知大结局--Raw通知 为什么叫大结局呢?因为推送通知服务就只有三种,前面扯了两种,就剩下一种--Raw通知. 前面我们通过两节的动手实验,相信大家 ...
- Windows Phone开发(38):动画之PointAnimation
原文:Windows Phone开发(38):动画之PointAnimation PointAnimation也是很简单的,与前面说到的两个Animation是差不多的,属性也是一样的,如By.Fro ...
- HDU1176_免费馅饼【号码塔】
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- coco2dx c++ HTTP实现
coco2dx c++ HTTP实现 达到的结果如下面的 iPhone截图 android 日志截图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdnBp ...
- PDO进行sql报表编制结果集介绍及操作(两)
<span style="font-size:18px;">一个:运行准备好的语句和绑定参数insert try { $pdo=new PDO("mysql: ...
- SoccerLeagueDB
create table if not exists League ( lid int primary key auto_increment, lyear int not null, s ...