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)的更多相关文章

  1. Multi-View 3D Reconstruction with Geometry and Shading——Part-2

    From PhDTheses Multi-View 3D Reconstruction with Geometry and Shading 我们的主要目标是只利用图像中的信息而没有额外的限制或假设来得 ...

  2. Multi-View 3D Reconstruction with Geometry and Shading——Part-1

    From PhDTheses Multi-View 3D Reconstruction with Geometry and Shading 计算机视觉的主要任务就是利用图像信息能智能理解周围的世界. ...

  3. 如何用webgl(three.js)搭建一个3D库房,3D密集架,3D档案室,-第二课

    闲话少叙,我们接着第一课继续讲(http://www.cnblogs.com/yeyunfei/p/7899613.html),很久没有做技术分享了.很多人问第二课有没有,我也是抽空写一下第二课. 第 ...

  4. webgl(three.js)实现室内三维定位,3D定位,3D楼宇bim、实时定位三维可视化解决方案——第十四课(定位升级版)

    序: 还是要抽出时间看书的,迷上了豆豆的作品,最近在看<天幕红尘>,书中主人公的人生价值观以及修为都是让我惊为叹止.很想成为那样的人,但是再看看自己每天干的事,与时间的支配情况,真是十分的 ...

  5. 教你调节Boom 3D的3D音效强度,让音乐更带感

    Boom 3D的专业3D环绕技术,让用户能全身心地沉浸在立体音效中.无论是聆听音乐,还是观赏电影,立体音效都能为人们带来更加真实的听觉感触. 那么,Boom 3D的3D环绕功能到底能给用户带来怎样的体 ...

  6. 如何用webgl(three.js)搭建一个3D库房,3D密集架,3D档案室(升级版)

    很长一段时间没有写3D库房,3D密集架相关的效果文章了,刚好最近有相关项目落地,索性总结一下 与之前我写的3D库房密集架文章<如何用webgl(three.js)搭建一个3D库房,3D密集架,3 ...

  7. 如何用webgl(three.js)搭建一个3D库房,3D仓库,3D码头,3D集装箱可视化孪生系统——第十五课

    序 又是快两个月没写随笔了,长时间不总结项目,不锻炼文笔,一开篇,多少都会有些生疏,不知道如何开篇,如何写下去.有点江郎才尽,黔驴技穷的感觉. 写随笔,通常三步走,第一步,搭建框架,先把你要写的内容框 ...

  8. 如何用webgl(three.js)搭建一个3D库房,3D仓库3D码头,3D集装箱,车辆定位,叉车定位可视化孪生系统——第十五课

    序 又是快两个月没写随笔了,长时间不总结项目,不锻炼文笔,一开篇,多少都会有些生疏,不知道如何开篇,如何写下去.有点江郎才尽,黔驴技穷的感觉. 写随笔,通常三步走,第一步,搭建框架,先把你要写的内容框 ...

  9. webgl(three.js)3D光伏,3D太阳能能源,3D智慧光伏、光伏发电、清洁能源三维可视化解决方案——第十六课

    序: 能源是文明和发展的重要保障,人类命运不可避开的话题,无论是战争还是发展,都有它存在的身影.从石器时代到现代文明,人类的能源应用在进步,也在面临能源枯竭的危机与恐惧,而开发与应用可再生能源才是解决 ...

  10. 如何使用webgl(three.js)实现3D储能,3D储能站,3D智慧储能、储能柜的三维可视化解决方案——第十七课

    前言 上节课我们讲了<3D光伏发电>,与之配套的就是能量存储 这节课我们主要讲讲储能,储能站,在分布式能源系统中起到调节用对电的尖峰平谷进行削峰填谷的作用.特别是小型储能站,更加灵活,因地 ...

随机推荐

  1. 【CS Round #44 (Div. 2 only) A】Frequent Numbers

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 大水题 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #include &l ...

  2. 问题解决:在js中绑定onclick事件为什么不加括号,在html代码中必须要加?(转载)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 26718汉字,gbk是23940个汉字,gb18030有76556个汉字

    1 a 厑 吖 呵 啊 嗄 嬶 腌 錒 锕 阿 仰 卬 岇 昂 昻 枊 盎 肮 腌 軮 醠 雵 骯 侒 俺 儑 匎 匼 厂 厈 唵 啽 垵 埯 堓 媕 安 屵 岸 峎 峖 广 庵 按 揞 晻 暗 案 ...

  4. iOS开发中WiFi相关功能总结

    http://www.cocoachina.com/ios/20160715/17022.html 投稿文章,作者:Haley_Wong(简书) 查漏补缺集是自己曾经做过相关的功能,但是重做相关功能或 ...

  5. JSP Web第五章整理复习 JSP访问数据库

    P164  例5-1  常用SQL语句 P178  数据库连接池 (1)连接池的作用 存储多个数据库连接对象,当程序需要时,从池中获取1个连接,程序执行完成后再还给连接池.避免数据库连接建立.关闭的开 ...

  6. PHP闭包实现函数的自调用实现递归

    根据pathinfo访问对应得controller,如ip:port/home/index/index则会访问home目录下的IndexController的index方法:如果不指定pathinfo ...

  7. PHP核心编程--站内搜索

    一.         站内搜索 前台页面: 在index.php页面中添加一个表单,输入搜索框 后台页面: 将index.php另存为search.php 对于搜索的 分页关键代码: 高亮关键字 相关 ...

  8. Leetcode824.Goat Latin山羊拉丁文

    给定一个由空格分割单词的句子 S.每个单词只包含大写或小写字母. 我们要将句子转换为 "Goat Latin"(一种类似于 猪拉丁文 - Pig Latin 的虚构语言). 山羊拉 ...

  9. springboot 启动配置原理【转】【补】

    创建应用 几个重要的事件回调机制  , 配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunL ...

  10. .net 数据表格显示控件

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/chenjinge7/article/details/30470609 1. GridView 控件 ...