uva 11275 3D Triangles (3D-Geometry)
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2250
判断两个空间中的三角形是否有公共点。
代码如下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm> using namespace std; struct Point3 {
double x[];
Point3() {}
Point3(double *_x) { for (int i = ; i < ; i++) x[i] = _x[i];}
} ;
typedef Point3 Vec3; Vec3 operator + (Vec3 a, Vec3 b) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] + b.x[i];
return ret;
}
Vec3 operator - (Vec3 a, Vec3 b) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] - b.x[i];
return ret;
}
Vec3 operator * (Vec3 a, double p) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] * p;
return ret;
}
Vec3 operator / (Vec3 a, double p) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[i] / p;
return ret;
} const double EPS = 1e-;
inline int sgn(double x) { return (x > EPS) - (x < -EPS);} bool operator < (Point3 a, Point3 b) {
for (int i = ; i < ; i++) {
if (sgn(a.x[i] - b.x[i])) return a.x[i] < b.x[i];
}
return true;
}
bool operator == (Point3 a, Point3 b) {
for (int i = ; i < ; i++) {
if (sgn(a.x[i] - b.x[i])) return false;
}
return true;
} double dotDet(Vec3 a, Vec3 b) {
double ret = 0.0;
for (int i = ; i < ; i++) ret += a.x[i] * b.x[i];
return ret;
}
inline double dotDet(Point3 o, Point3 a, Point3 b) { return dotDet(a - o, b - o);}
inline Vec3 crossDet(Vec3 a, Vec3 b) {
Vec3 ret;
for (int i = ; i < ; i++) ret.x[i] = a.x[(i + ) % ] * b.x[(i + ) % ] - b.x[(i + ) % ] * a.x[(i + ) % ];
return ret;
}
inline Vec3 crossDet(Point3 o, Point3 a, Point3 b) { return crossDet(a - o, b - o);}
inline double vecLen(Vec3 x) { return sqrt(dotDet(x, x));}
inline double angle(Vec3 a, Vec3 b) { return acos(dotDet(a, b) / vecLen(a) / vecLen(b));}
inline double ptDis(Point3 a, Point3 b) { return vecLen(a - b);}
inline double triArea(Point3 a, Point3 b, Point3 c) { return vecLen(crossDet(a, b, c));}
inline Vec3 vecUnit(Vec3 x) { return x / vecLen(x);} struct Plane {
Point3 p;
Vec3 n;
Plane() {}
Plane(Point3 p, Vec3 n) : p(p), n(n) {}
Plane(Point3 a, Point3 b, Point3 c) { p = a; n = crossDet(b - a, c - a);}
} ;
inline double pt2Plane(Point3 p, Point3 p0, Vec3 n) { return dotDet(p - p0, n) / vecLen(n);}
inline double pt2Plane(Point3 p, Plane P) { return pt2Plane(p, P.p, P.n);}
inline Point3 ptOnPlane(Point3 p, Point3 p0, Vec3 n) { return p + n * pt2Plane(p, p0, n);}
inline Point3 ptOnPlane(Point3 p, Plane P) { return ptOnPlane(p, P.p, P.n);}
inline bool ptInPlane(Point3 p, Point3 p0, Vec3 n) { return sgn(dotDet(p - p0, n)) == ;}
inline bool ptInPlane(Point3 p, Plane P) { return ptInPlane(p, P.p, P.n);} int linePlaneIntersect(Point3 s, Point3 t, Point3 p0, Vec3 n, Point3 &x) {
double res1 = dotDet(n, p0 - s);
double res2 = dotDet(n, t - s);
if (sgn(res2) == ) {
if (ptInPlane(s, p0, n)) return ;
return ;
}
x = s + (t - s) * (res1 / res2);
return ;
} bool ptInTri(Point3 p, Point3 *tri) {
double area = triArea(tri[], tri[], tri[]);
double sum = 0.0;
for (int i = ; i < ; i++) sum += triArea(p, tri[i], tri[(i + ) % ]);
return sgn(sum - area) == ;
} bool triSegIntersect(Point3 *tri, Point3 s, Point3 t) {
Vec3 n = crossDet(tri[], tri[], tri[]);
if (sgn(dotDet(n, t - s)) == ) return false;
else {
double k = dotDet(n, tri[] - s) / dotDet(n, t - s);
if (sgn(k) < || sgn(k - ) > ) return false;
Point3 x = s + (t - s) * k;
return ptInTri(x, tri);
}
} Point3 tri[][]; bool check() {
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
if (triSegIntersect(tri[i], tri[i ^ ][j], tri[i ^ ][(j + ) % ])) return true;
}
}
return false;
} int main() {
// freopen("in", "r", stdin);
int n;
cin >> n;
while (n--) {
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
for (int k = ; k < ; k++) {
cin >> tri[i][j].x[k];
}
}
}
cout << check() << endl;
}
return ;
}
——written by Lyon
uva 11275 3D Triangles (3D-Geometry)的更多相关文章
- Multi-View 3D Reconstruction with Geometry and Shading——Part-2
From PhDTheses Multi-View 3D Reconstruction with Geometry and Shading 我们的主要目标是只利用图像中的信息而没有额外的限制或假设来得 ...
- Multi-View 3D Reconstruction with Geometry and Shading——Part-1
From PhDTheses Multi-View 3D Reconstruction with Geometry and Shading 计算机视觉的主要任务就是利用图像信息能智能理解周围的世界. ...
- 如何用webgl(three.js)搭建一个3D库房,3D密集架,3D档案室,-第二课
闲话少叙,我们接着第一课继续讲(http://www.cnblogs.com/yeyunfei/p/7899613.html),很久没有做技术分享了.很多人问第二课有没有,我也是抽空写一下第二课. 第 ...
- webgl(three.js)实现室内三维定位,3D定位,3D楼宇bim、实时定位三维可视化解决方案——第十四课(定位升级版)
序: 还是要抽出时间看书的,迷上了豆豆的作品,最近在看<天幕红尘>,书中主人公的人生价值观以及修为都是让我惊为叹止.很想成为那样的人,但是再看看自己每天干的事,与时间的支配情况,真是十分的 ...
- 教你调节Boom 3D的3D音效强度,让音乐更带感
Boom 3D的专业3D环绕技术,让用户能全身心地沉浸在立体音效中.无论是聆听音乐,还是观赏电影,立体音效都能为人们带来更加真实的听觉感触. 那么,Boom 3D的3D环绕功能到底能给用户带来怎样的体 ...
- 如何用webgl(three.js)搭建一个3D库房,3D密集架,3D档案室(升级版)
很长一段时间没有写3D库房,3D密集架相关的效果文章了,刚好最近有相关项目落地,索性总结一下 与之前我写的3D库房密集架文章<如何用webgl(three.js)搭建一个3D库房,3D密集架,3 ...
- 如何用webgl(three.js)搭建一个3D库房,3D仓库,3D码头,3D集装箱可视化孪生系统——第十五课
序 又是快两个月没写随笔了,长时间不总结项目,不锻炼文笔,一开篇,多少都会有些生疏,不知道如何开篇,如何写下去.有点江郎才尽,黔驴技穷的感觉. 写随笔,通常三步走,第一步,搭建框架,先把你要写的内容框 ...
- 如何用webgl(three.js)搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课
序 又是快两个月没写随笔了,长时间不总结项目,不锻炼文笔,一开篇,多少都会有些生疏,不知道如何开篇,如何写下去.有点江郎才尽,黔驴技穷的感觉. 写随笔,通常三步走,第一步,搭建框架,先把你要写的内容框 ...
- webgl(three.js)3D光伏,3D太阳能能源,3D智慧光伏、光伏发电、清洁能源三维可视化解决方案——第十六课
序: 能源是文明和发展的重要保障,人类命运不可避开的话题,无论是战争还是发展,都有它存在的身影.从石器时代到现代文明,人类的能源应用在进步,也在面临能源枯竭的危机与恐惧,而开发与应用可再生能源才是解决 ...
- 如何使用webgl(three.js)实现3D储能,3D储能站,3D智慧储能、储能柜的三维可视化解决方案——第十七课
前言 上节课我们讲了<3D光伏发电>,与之配套的就是能量存储 这节课我们主要讲讲储能,储能站,在分布式能源系统中起到调节用对电的尖峰平谷进行削峰填谷的作用.特别是小型储能站,更加灵活,因地 ...
随机推荐
- 洛谷P1352 没有上司的舞会 [2017年5月计划 清北学堂51精英班Day3]
P1352 没有上司的舞会 题目描述 某大学有N个职员,编号为1~N.他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子 结点的直接上司.现在有个周年庆宴会,宴会每邀请来一个职 ...
- Linux下安装ssdb
安装ssdb wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip unzip master cd ...
- placeholder改变输入框字体颜色
::-webkit-input-placeholder { color: #888;}:-moz-placeholder { color: #888;}::-moz-placeholder{col ...
- jquery判断页面网址是否有效
方法一:(jQuery方法: 适用所有浏览器) HTML页面: <!DOCTYPE html><html><head lang="en"> &l ...
- vue中is的作用和用法
回顾vue官方文档的过程中发现了is这个特性,虽然以我的写代码风格实在用不上,不过还是记录一下这个知识点 is的作用 <ul> <li></li> <li&g ...
- windows下MySQL 5.7.19版本sql_mode=only_full_group_by问题
用到GROUP BY 语句查询时出现 which is not functionally dependent on columns in GROUP BY clause; this is incomp ...
- XML配置里的Bean自动装配与Bean之间的关系
需要在<bean>的autowire属性里指定自动装配的模式 byType(根据类型自动装配) byName(根据名称自动装配) constructor(通过构造器自动装配) 名字须与属性 ...
- umount报错解决device is busy
umount –a 报错device is busy如图 df -h 执行 umount -l /dev/sdk1 fuser -m -v /cache10 再查看卸载了
- 重磅!容器集群监控利器 阿里云Prometheus 正式免费公测
Prometheus 作为容器生态下集群监控的首选方案,是一套开源的系统监控报警框架.它启发于 Google 的 borgmon 监控系统,并于 2015 年正式发布.2016 年,Prometheu ...
- 洛谷 P3768 简单的数学题 (莫比乌斯反演)
题意:求$(\sum_{i=1}^{n}\sum_{j=1}^{n}ijgcd(i,j))mod p$(p为质数,n<=1e10) 很显然,推式子. $\sum_{i=1}^{n}\sum_{j ...