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个点.求三维凸包面积. 题解 增量法,看了一天,还是没有完全懂. 上板 ...
随机推荐
- hdu1281+hdu2819(最大匹配数)
分析:将行和列缩点,即行对应二分图的X部,列对应二分图的Y部,然后交点为连接该行和该列的一条边.匹配时每点都会把整行整列占了,因此就不会出现冲突了. 传送门:hdu1281 棋盘游戏 #include ...
- AngularJS是为了克服HTML在构建应用上的不足而设计的
AngularJS中文网:http://www.apjs.net/ 简介 AngularJS是为了克服HTML在构建应用上的不足而设计的.HTML是一门很好的为静态文本展示设计的声明式语言,但要构 ...
- hdu2606(递推)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2606 题意: 用1*1,2*2,3*3,4*4的正方形填充4*n的矩形, 问有多少种不同填法. 分析 ...
- IDEA系统提示中文乱码问题及解决
近期要切换到IDEA开发, 在输出界面发现打印小方格, 或者乱码, 是由于字体不支持中文, 选择一个支持中文的就正常了.(由于IDEA在国内下载错误信息会用中文显示. 而之前Eclipse错误都是英文 ...
- TextView中如何支持html标签,放置图片和动作标签
TextView文本框和输入框几乎是一个正常的带界面的可交互的Android应用的基本组成 TextView主要作用是显示文本内容,其实还可以显示图片,当然有必要的话还可以为文本内容添加动作相应用户的 ...
- openstack学习笔记一 虚拟机启动过程代码跟踪
openstack学习笔记一 虚拟机启动过程代码跟踪 本文主要通过对虚拟机创建过程的代码跟踪.观察虚拟机启动任务状态的变化,来透彻理解openstack各组件之间的作用过程. 当从horizon界面发 ...
- Android Studio使用心得 - 简单介绍与环境配置
FBI Warning:欢迎转载,但请标明出处:http://blog.csdn.net/codezjx/article/details/38544823,未经本人允许请勿用于商业用途.感谢支持! 关 ...
- 可删除超炫&多种特效的Card视图(改造自cardsui-for-android开源项目),提供DEMO下载
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990).谢谢支持! 实例Demo下载地址在本文最后 简介 这个Demo主要是使用了cardsui ...
- Qt4.8在Windows下的三种编程环境搭建
Qt4.8在Windows下的三种编程环境搭建 Qt的版本是按照不同的图形系统来划分的,目前分为四个版本:Win32版,适用于Windows平台:X11版,适合于使用了X系统的各种Linux和Unix ...
- 百度mp3接口
歌曲ID 具体信息接口:http://tingapi.ting.baidu.com/v1/restserver/ting? from=android&version=2.4.0&met ...