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个点.求三维凸包面积. 题解 增量法,看了一天,还是没有完全懂. 上板 ...
随机推荐
- hdu4738(双连通分量)
传送门:Caocao's Bridges 题意:n个岛,曹操在一些岛之间建了一些桥,每个桥上有一些士兵把守,周瑜只有一个炸弹只能炸掉一个桥,并能使一些岛被孤立出来,炸弹需要士兵带过去,士兵的数量不能小 ...
- 俄罗斯方块游戏JavaScript代码
JavaScript代码俄罗斯方块游戏 早就听说网上有人仅仅用60行JavaScript代码写出了一个俄罗斯方块游戏,最近看了看,今天在这篇文章里面我把我做的分析整理一下(主要是以注释的形式). 我用 ...
- 使用Spring的JAVA Mail支持简化邮件发送(转)
闲来无事,翻看<Spring in Action>,发现Spring集成了对JAVA Mail的支持,有点小激动的看了一遍,嗯,话说真的简单了很多. Spring的邮件发送的核心是Mail ...
- jQuery UI 是建立在 jQuery JavaScript 库上的一组用户界面交互、特效、小部件及主题
jQuery UI 是建立在 jQuery JavaScript 库上的一组用户界面交互.特效.小部件及主题.无论您是创建高度交互的 Web 应用程序还是仅仅向窗体控件添加一个日期选择器,jQuery ...
- zoj3471(状压dp)
题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4257 题意:不超过10种气体,两两之间相互碰撞可以产生一定的能量,如 ...
- OpenStack 中的neutron-server启动过程
neutron-server是neutron的核心组件之中的一个.负责直接接收外部请求,然后调用后端对应plugin进行处理. 其核心启动过程代码主要在neutron.server包中. __init ...
- 创建并使用静态库(ar 命令)
创建并使用静态库(ar 命令) archive命令的功能是:创建或改动归档文件或者从归档文件里析取信息.能够简单的理解为一个打包工具,将成员文件依照一定的规则构建到.a文件里, ...
- SE 2014年5月5日
如图配置 某企业网络规划图(三台交换设备/三台路由设备) 接入层 SW1 连接终端用户 汇聚层 SW2 SW3 核心层 R1 R2 R5 1. 如图 SW1 SW2 SW3 物理链路两两相连接,网络中 ...
- JS验证身份证的合法性
//验证身份证的合法性 function IdentityCodeValid(code) { var city={11:"北京",12:"天津",13:&quo ...
- Net分布式系统
Net分布式系统 Net分布式系统之三:Keepalived+LVS+Nginx负载均衡之高可用 摘要: 上一篇写了nginx负载均衡,此篇实现高可用(HA).系统整体设计是采用Nginx做负载均衡, ...