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个点.求三维凸包面积. 题解 增量法,看了一天,还是没有完全懂. 上板 ...
随机推荐
- jQuery 复制节点的元素实现加入到购物车功能
描写叙述: 用户点击左边div中的商品,相应商品会自己主动加入到右面的div中,类似电子商城中的加入到购物车功能. 主要用到了jquery中的复制节点功能,基本原理是首先获取点击的元素,然后将对应信息 ...
- 10324 - Zeros and Ones
Problem N Zeros and Ones Input: standard input Output: standard output Time Limit: 2 seconds Memory ...
- 你属于几K(千)?
月薪2k.对出勤率负责:5k,对按时完毕率负责:8k,对质量负责:12k.对小团队的情绪负责:16k,对到款率负责:20k,要想着怎么保住自己的饭碗.40k.保住部门.100k.保住大部门:100k+ ...
- 腾讯视频QLV格式转换mp4的方法
腾讯视频QLV格式转换mp4的方法不知道大家知不知道用?喜欢用腾讯视频的朋友应该都知道腾讯视频单独搞出了个QLV格式文件,只能用腾讯独有的腾讯视频软件才能播放,就算用格式工厂转换也不行,那么腾讯视频的 ...
- web框架之Spring-MVC环境搭建(转)
spring框架jar包 1.下载spring源包spring地址:http://www.springsource.org/download我下的是spring-framework-3.1.0.REL ...
- ubuntu下使用自带的openJDK查看java源码
如题 Ubuntu自带的OpenJDK仅仅有jre环境,不提供源代码,所以我们还是须要去下载. JDK6:http://download.java.net/openjdk/jdk6/ JDK7:htt ...
- Struts2 开发环境搭建
一.开发环境 eclipse+tomcat+struts-2.2.3 eclipse下载地址:http://www.eclipse.org/downloads/ tomca ...
- (转)SWT的CheckBoxTreeViewer的相关用法
最近在项目中需要用到遍历某个目录下所有文件,并按照树形结构展示,同时还需要提供对树形菜单的选择展开等操作.在eclipse中提供了CheckboxTreeViewer组件来满足所需要的功能 下面是需要 ...
- SCSI miniport 驾驶一个简单的框架
前段时间,只需用一台新电脑,由于资金有限没有匹配了心仪已久的SSD.我没感觉到飞翔的感觉,总不甘心,仔细想想.我死了相当大的存储,我们可以假设部分内存作为硬盘驱动器把它弄出来.不会比固态硬盘的速度快, ...
- CF552E 字符串 表达式求值
http://codeforces.com/contest/552/problem/E E. Vanya and Brackets time limit per test 1 second memor ...