主题链接:

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 的三维凸包要求的表面面积的更多相关文章

  1. POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心

    题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...

  2. hdu4273Rescue(三维凸包重心)

    链接 模板题已不叫题.. 三维凸包+凸包重心+点到平面距离(体积/点积)  体积-->混合积(先点乘再叉乘) #include <iostream> #include<cstd ...

  3. hdu4449Building Design(三维凸包+平面旋转)

    链接 看了几小时也没看懂代码表示的何意..无奈下来问问考研舍友. 还是考研舍友比较靠谱,分分钟解决了我的疑问. 可能三维的东西在纸面上真的不好表示,网上没有形象的题解,只有简单"明了&quo ...

  4. hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***

    新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...

  5. HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...

  6. bzoj 1209: [HNOI2004]最佳包裹 三维凸包

    1209: [HNOI2004]最佳包裹 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 160  Solved: 58[Submit][Status] ...

  7. bzoj 1964: hull 三维凸包 计算几何

    1964: hull 三维凸包 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 54  Solved: 39[Submit][Status][Discuss ...

  8. POJ 3528 求三维凸包表面积

    也是用模板直接套的题目诶 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include < ...

  9. BZOJ1209 [HNOI2004]最佳包裹 三维凸包 计算几何

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1209 题目概括 给出立体的n个点.求三维凸包面积. 题解 增量法,看了一天,还是没有完全懂. 上板 ...

随机推荐

  1. Mongodb中更新的学习小结

    今天继续很久没学习的mongodb的简单学习,今天来看的是更新.先来看简单的用法: use updatetest >switched to db updatetest 首先插入一下: db.th ...

  2. Windows下安装MySQLdb, Python操作MySQL数据库的增删改查

    这里的前提是windows上已经安装了MySQL数据库,且配置完成,能正常建表能操作. 在此基础上仅仅需安装MySQL-python-1.2.4b4.win32-py2.7.exe就ok了.仅仅有1M ...

  3. JavaFX的扩展控件库ControlsFX介绍

    声明:   本博客文章原创类别的均为个人原创,版权所有.转载请注明出处: http://blog.csdn.net/ml3947,另外本人的个人博客:http://www.wjfxgame.com. ...

  4. WPF-20:richtextbox相关操作(转)

    WPF中的richtextbox与winform中的richtextbox的使用不同,看看下面的基本操作: 一.取出richTextBox里面的内容  (1)将richTextBox的内容以字符串的形 ...

  5. cocos2d-x 旅程開始--(实现瓦片地图中的碰撞检測)

    转眼隔了一天了,昨天搞了整整一下午加一晚上,楞是没搞定小坦克跟砖头的碰撞检測,带着个问题睡觉甚是难受啊!还好今天弄成功了.只是感觉程序不怎么稳定啊.并且发现自己写的东西让我重写一遍的话我肯定写不出来. ...

  6. 代码重构 & 代码中的坏味道

    1.重构 1.1 为什么要重构 1.1.1 改进程序设计 程序员为了快速完成任务,在没有完全理解整体架构之前就开始写代码, 导致程序逐渐失去自己的结构.重构则帮助重新组织代码,重新清晰的体现 程序结构 ...

  7. ajax相关体会

    参考原文: 例子:http://blog.csdn.net/beijiguangyong/article/details/7725596 原理讲解:http://www.cnblogs.com/min ...

  8. Gradle 修改 Maven 仓库地址(转)

    近来迁移了一些项目到Android Studio,采用Gradle构建确实比原来的Ant方便许多.但是编译时下载依赖的网速又着实令人蛋疼不已. 如果能切换到国内的Maven镜像仓库,如开源中国的Mav ...

  9. hdu2818行列匹配+排序

    题意:给定一个矩阵,矩阵上有的数字是1,有的是0,给定两种操作,交换某两行或者某两列,问是否能置换出对角线为1的矩阵 题解:能够置换出对角线是1的矩形要求有n个1既不在同一行也不再同一列,即行列匹配, ...

  10. Windows Phone开发(10):常用控件(上)

    原文:Windows Phone开发(10):常用控件(上) Windows Phone的控件有几个来源,和传统的桌面应用程序开发或Web开发一样,有默认提供的控件和第三方开者发布的控件.一般而言,如 ...